OpenCv:绘制一个白色填充的多边形
我想在黑色 IplImage 中绘制一个具有任意角度的白色填充多边形。我知道存在诸如 createCircle 之类的函数,但我找不到类似的多边形函数。 我发现 这个 ,但它的使用很糟糕,我的意思是,我不必只是为了在黑色背景上绘制一个简单的白色多边形而陷入困境......!
我在 OpenCV 文档中找到的示例:
void MyPolygon( Mat img )
{
int lineType = 8;
/** Create some points */
Point rook_points[1][20];
rook_points[0][0] = Point( w/4.0, 7*w/8.0 );
rook_points[0][1] = Point( 3*w/4.0, 7*w/8.0 );
rook_points[0][2] = Point( 3*w/4.0, 13*w/16.0 );
rook_poi /*** blablabla **/
rook_points[0][19] = Point( w/4.0, 13*w/16.0) ;
const Point* ppt[1] = { rook_points[0] };
int npt[] = { 20 };
fillPoly( img,
ppt,
npt,
1,
Scalar( 255, 255, 255 ),
lineType );
}
基本上,我的问题是,如何将 CvBox2D 放入 fillPoly 中,以从中获取蒙版并最终设置我需要的“带角度的 ROI”?
I'd like to draw a white filled polygon, with arbitrary angle, in a black IplImage. I know there exists function such as createCircle, but I can't find something similar for polygons.
I found this , but the use of it is awful, I mean I shouldn't have to go into this just to draw one simple white polygon on a black background...!
The example I found on the OpenCV documentation:
void MyPolygon( Mat img )
{
int lineType = 8;
/** Create some points */
Point rook_points[1][20];
rook_points[0][0] = Point( w/4.0, 7*w/8.0 );
rook_points[0][1] = Point( 3*w/4.0, 7*w/8.0 );
rook_points[0][2] = Point( 3*w/4.0, 13*w/16.0 );
rook_poi /*** blablabla **/
rook_points[0][19] = Point( w/4.0, 13*w/16.0) ;
const Point* ppt[1] = { rook_points[0] };
int npt[] = { 20 };
fillPoly( img,
ppt,
npt,
1,
Scalar( 255, 255, 255 ),
lineType );
}
Basically, my question is, how do I put a CvBox2D into fillPoly, to get a mask out of it and finally set the "ROI with angle" that I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样:
Like this:
对于绘制实心填充矩形,请在绘图函数 == CV_FILLED 中使用厚度,这将为您提供一个实心填充矩形&对于任何多边形形状都是如此......
cvRectangle(img,
CV点(x1,y1),
CV点(x2,y2),
CV_RGB(0, 255, 0), CV_FILLED, 8, 0);
For Drawing solid filled rectangle Use thickness in draw function == CV_FILLED which will give you a solid filled rectangle & it true for any polygon shape.....
cvRectangle(img,
cvPoint(x1, y1),
cvPoint(x2,y2),
CV_RGB(0, 255, 0), CV_FILLED, 8, 0);