我正在编写C( not 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中的错误参数(不支持的序列类型)。
我told问题是没有设置将序列标识为折线的标志,我已经尝试了建议hull->flags = hull->flags | 512
,但可能是在2008年和2008年之间的某些时候标志发生了变化。现在,因为那不起作用。
所以问题是:如何在cvConvexHull2()的结果上使用cvApproxPoly()?我应该使用什么数据类型,以及cvApproxPoly()的正确参数是什么?
答案 0 :(得分:3)
我认为您缺少存储参数:
cvFindContours(<CvArr *image>, <CvMemStorage *storage>, <CvSeq **first_contour>, <int header_size>, <int mode>, <int method>, <CvPoint offset>)
使用
进行测试CvMemStorage *storage = cvCreateMemStorage(0);
cvFindContours( img, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, CvPoint(0,0) );
hull = cvConvexHull2( contours, storage, CV_CLOCKWISE, 0 );