OpenCV:用角度设置 ROI?
我想使用 ROI 将图像中找到的多边形复制到新图像中。我希望这个多边形能够完全适合新图像。 到目前为止,我使用了 ROI,但我注意到没有考虑角度,一旦我旋转我想要检测的对象,这就会给我带来不好的结果。我需要这个对象单独进行进一步分析...
这就是我所做的:
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);
/*****/
}
有人知道如何将角度整合到投资回报率中吗?是否可以采取其他措施?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须从您的
RotatedRect
制作一个遮罩,并使用该遮罩复制您的图像。编辑
如何制作遮罩:
创建一个与原始尺寸相同的新图像,但只有一个通道8U。
使用您喜欢的方法将其设置为零。
使用您喜欢的绘图功能绘制矩形、多边形、圆形或任何您想要用作 ROI 的内容。例如,
DrawPoly
。确保用 255 填充该数字。显示图像。它应该在黑色背景上包含一个白色多边形。
将其用作掩码参数。
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.