OpenCV: set ROI with angle?

I would like to use ROI to copy the found polygon in the image to a new image. I would like this polygon to exactly match the new image. So far I have used ROI, but I noticed that the angle is not taken into account, which gives me a bad result as soon as I rotate the object that I found. I need this object alone for further analysis ...

That's what I'm doing:

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 an angle into a ROI? Is it possible to do otherwise?

Thanks!

+1
source share
1 answer

You must make a mask from RotatedRect and copy the image using the mask.

EDIT

How to make a mask:

Create a new image with the same size as the original, but only one 8U channel. Set it to zero using the selected method. Draw your rectangle, polygon, circle, or whatever you want to use as an ROI, with your preferred drawing function. DrawPoly , for example. Make sure you fill in the number 255. Image display. It should contain a white polygon on a black backing.

Use it as a mask parameter.

+3
source

All Articles