CTZStef
CTZStef

Reputation: 1715

OpenCV : set ROI with angle?

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...

Here is what I do:

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);

        /*****/
    }

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

Thanks!

Upvotes: 1

Views: 2516

Answers (1)

Sam
Sam

Reputation: 20056

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

EDIT

How to make a mask:

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.

Use it as mask parameter.

Upvotes: 3

Related Questions