cvBoundingRect not working

cvBoundingRect not working

本文关键字:working not cvBoundingRect      更新时间:2023-10-16

我正在传递cvFindContours即轮廓到cvBoundingRect的输出。但是它给出了这个错误:

OpenCV错误:cvBoundingRect中的坏参数(不支持的序列类型),文件/home/z/src/OpenCV-2.4.2/modules/imgproc/src/shapedescr.cpp, 950行抛出'cv::Exception'实例后调用终止什么():/home/z/src/opencv -2.4.2/modules/imgproc/src/shapedescr.cpp:950:错误:(-5)函数cvBoundingRect中不支持的序列类型

代码如下:

CvRect rect;
cvFindContours( imgB, g_storage, &contours,sizeof(CvContour),CV_RETR_LIST, CV_CHAIN_CODE,cvPoint(0,0));
if(contours)
{cvDrawContours(img_B,contours, CV_RGB(250,0,0), CV_RGB(0,0,250),1,2,8);
rect=cvBoundingRect(contours);
}

请告诉我这个错误的原因。解决方案是什么?由于

cvBoundingRect()取1个轮廓,您将把它们全部馈送到它

从berak离开的地方开始,CvSeq** first_contour是你提供的函数。

指针first_contour由函数填充。它将包含指向第一个最外层轮廓的指针,如果没有轮廓,则为NULL检测到(如果图像是完全黑的)。其他轮廓可能是通过h_next和v_next链接从first_contour到达。

所以你需要这样写:

CvSeq* contour = *contours;
while (contour != NULL)
{
    //insert boundingbox and other code
    contour = contour->h_next;
}

好了,我找到答案了。下面是正确的方法:

http://singhgaganpreet.com/tag/cvboundingrect-example/