gpt4 book ai didi

c - 在 OpenCV 中对 cvConvexHull2() 的结果使用 cvApproxPoly()

转载 作者:太空宇宙 更新时间:2023-11-03 21:06:24 25 4
gpt4 key购买 nike

我正在编写 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 );

其中 imgcontours 都是有效的。这些行之间还有很多内容,但它的 FindContours 部分已经过测试可以正常工作。

此代码抛出异常:错误:cvApproxPoly 中的错误参数(不支持的序列类型)

我是 told问题是未设置将序列标识为折线的标志,我已经尝试了建议 hull->flags = hull->flags | 512 但大概标志在 2008 年到现在之间的某个时间发生了变化,因为那不起作用。

所以问题是:如何在 cvConvexHull2() 的结果上使用 cvApproxPoly()?我应该使用什么数据类型,cvApproxPoly() 的正确参数是什么?

最佳答案

我认为您缺少存储参数:

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 );

关于c - 在 OpenCV 中对 cvConvexHull2() 的结果使用 cvApproxPoly(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9186742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com