OpenCV : set ROI with angle?
Asked Answered
V

1

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!

Venial answered 31/1, 2012 at 4:19 Comment(0)
H
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.

Hirsh answered 31/1, 2012 at 6:42 Comment(4)
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 !!!Venial
have a look at this: nashruddin.com/OpenCV_Circular_ROI it creates a circular ROI, but the way to procede is the same in your caseAideaidedecamp
Did you read this page? opencv.itseez.com/modules/core/doc/drawing_functions.htmlHirsh
And it's a good idea to explore the whole opencv.itseez.com site. AYou cannot but learn a lot of things hereHirsh

© 2022 - 2024 — McMap. All rights reserved.