设置角度的投资回报率

设置角度的投资回报率

本文介绍了OpenCV:设置角度的投资回报率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ROI将图像中找到的多边形复制到新图像中.我希望此多边形完全适合新图像.到目前为止,我使用了ROI,但是我注意到没有考虑角度,一旦旋转希望检测的对象,就会给我带来不好的结果.我只需要这个对象就可以进行进一步的分析...

I'd like to use a ROI to copy a found polygon in an image, into a new image. I'd like this polygon to fit exactly in the new image.So far I used ROI, but I noticed that the angle is not taken into account, which give me bad result as soon as I rotate the object I whish to detect. I need this object alone for further analysis...

这是我的工作:

while(/****/)
{
    CvSeq* approximatedContour = cvApproxPoly(currentContour,
                                              sizeof(CvContour),
                                              0,
                                              CV_POLY_APPROX_DP,
                                              8);

    etiquetteBox = cvMinAreaRect2(approximatedContour);
    CvSize2D32f sizeEtiquette = etiquetteBox.size;

    if(/****/)
    {
        CvPoint2D32f boxPoints[4];
        cvBoxPoints(etiquetteBox, boxPoints);

        cvSetImageROI(thresImg,cvRect((int)boxPoints[1].x, (int)boxPoints[1].y,
                      (int)sizeEtiquette.width,(int)sizeEtiquette.height));

        cvResize(thresImg,thresImgResized);

        /*****/
    }

有人知道如何将角度整合到ROI中吗?可以这样做吗?

Does anyone know how to integrate angle into ROI? Is it possible to do otherwise?

谢谢!

推荐答案

您必须使用RotatedRect制作遮罩,并使用遮罩复制图像.

You must make a mask from your RotatedRect, and copy your image with the mask.

编辑

如何制作口罩:

创建一个与原始图像大小相同的新图像,但是只有一个8U通道.使用您的首选方法将其设置为零.使用您的首选绘图功能,绘制矩形,多边形,圆形或任何您想用作ROI的对象.例如,DrawPoly.确保用255填充数字.显示图像.它应该在黑色的背景上包含一个白色的多边形.

Create a new image with the same size as the original, but only one channel 8U.Set it to zero with your preffered method.Draw your rectangle, polygon, circle, or whatever you want to use as ROI, with your preffered drawing function. DrawPoly, by example. Make sure you fill the figure with 255.Display the image. It should contain a white polygon on a black bacground.

将其用作掩码参数.

这篇关于OpenCV:设置角度的投资回报率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:07