1

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!

CTZStef
  • 1,675
  • 2
  • 18
  • 47

1 Answers1

3

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.

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Sam
  • 19,708
  • 4
  • 59
  • 82
  • Hi Vasile, how do you do it? Using cvCopy? If I have to use cvCopy, let thresImg be the first parameter, rotatedRect the third, as a mask, what would be the second parameter (dest)? Is it, if I understand well, an IplImage the size of the mask?? Thx !!! – CTZStef Jan 31 '12 at 13:27
  • 1
    have a look at this: http://nashruddin.com/OpenCV_Circular_ROI it creates a circular ROI, but the way to procede is the same in your case – andrea Jan 31 '12 at 14:18
  • Did you read this page? http://opencv.itseez.com/modules/core/doc/drawing_functions.html – Sam Jan 31 '12 at 14:20
  • And it's a good idea to explore the whole http://opencv.itseez.com site. AYou cannot but learn a lot of things here – Sam Jan 31 '12 at 14:20