在 OpenCV 中对 cvConvexHull2() 的结果使用 cvApproxPoly()
我正在编写 C(不是 C++)代码来在矩形轮廓上运行凸包。 (大大简化的)代码如下所示:
CvSeq* contours;
CvSeq* hull;
cvFindContours( img, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, CvPoint(0,0) );
hull = cvConvexHull2( contours, storage, CV_CLOCKWISE, 0 );
其中 img
和 contours
都是有效的。这些行之间还有很多内容,但其中的 FindContours 部分已经过测试可以正常工作。
此代码抛出异常:错误:cvApproxPoly 中的参数错误(不支持的序列类型)。
我被告知问题是标识序列的标志由于未设置折线,我尝试了建议 hull->flags = hull->flags | 512
但大概这些标志在 2008 年至今的某个时间发生了变化,因为那不起作用。
所以问题是:如何在 cvConvexHull2() 的结果上使用 cvApproxPoly() ?我应该使用什么数据类型,cvApproxPoly() 的正确参数是什么?
I'm writing C (not C++) code to run convex hull on contours of rectangles. The (greatly simplified) code for that looks like this:
CvSeq* contours;
CvSeq* hull;
cvFindContours( img, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, CvPoint(0,0) );
hull = cvConvexHull2( contours, storage, CV_CLOCKWISE, 0 );
Where img
and contours
are both valid. There is a lot more between these lines, but the FindContours portion of it has been tested to work.
This code throws exception: Error: Bad argument (Unsupported sequence type) in cvApproxPoly.
I'm told that the problem is that the flag that identifies the sequence as a polyline is not set, and I have tried the suggestion hull->flags = hull->flags | 512
but presumably the flags have changed sometime between 2008 and now, since that does not work.
So the question is: how do I use cvApproxPoly() on the results of a cvConvexHull2()? What data type should I use, and what are the proper arguments for cvApproxPoly()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您缺少存储参数:
测试使用
I think you are missing the storage parameter:
Test using