Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing OpenCV:水滴周围的轮廓不正确_Image Processing_Opencv_Contour_Blobs - Fatal编程技术网

Image processing OpenCV:水滴周围的轮廓不正确

Image processing OpenCV:水滴周围的轮廓不正确,image-processing,opencv,contour,blobs,Image Processing,Opencv,Contour,Blobs,我试图在二值图像中围绕斑点绘制轮廓,然而,有时候,openCV会围绕两个不同的斑点绘制单个轮廓。下面是一个例子。我如何解决这个问题? 在这里,它应该为右侧的blob绘制两个边界框,并分别为左侧的blob绘制一个边界框。我同意他们很近,但他们之间有足够的距离。我只是画外部轮廓,而不是树或列表。我还使用cvFindNextContour(轮廓扫描仪),因为这对于我的案例来说更容易实现 谢谢 编辑: “输出”窗口中显示的图像来自不同的函数,该函数仅执行图像减法。“轮廓”窗口中显示的图像位于函数ppl

我试图在二值图像中围绕斑点绘制轮廓,然而,有时候,openCV会围绕两个不同的斑点绘制单个轮廓。下面是一个例子。我如何解决这个问题?

在这里,它应该为右侧的blob绘制两个边界框,并分别为左侧的blob绘制一个边界框。我同意他们很近,但他们之间有足够的距离。我只是画外部轮廓,而不是树或列表。我还使用cvFindNextContour(轮廓扫描仪),因为这对于我的案例来说更容易实现

谢谢

编辑: “输出”窗口中显示的图像来自不同的函数,该函数仅执行图像减法。“轮廓”窗口中显示的图像位于函数pplfind()中。“输出”图像被传递到img_con()。 }

int pplfind(CVC轮廓扫描仪cscan,CvSize frSize){ 流文件;字符buff[50]; 打开(“box.txt”,of stream::app); int-ppl=0; CvSeq*c; IplImage*out=cvCreateImage(frSize,8,3); 而(c=cvFindNextContour(cscan)){ CvRect-box=cvBoundingRect(c,1);
如果((box.height>int(box.width*1.2))&&(box.height>20)){/&&(box.width我从未使用过
cvFindNextContour
,但在图像上运行
cvFindContours
CV_RETR\u EXTERNAL
似乎效果不错:

我使用OpenCV+Python,因此此代码可能对您没有用处,但为了完整性起见,这里是:

contours = cv.findContours(img, cv.CreateMemStorage(0), mode=cv.CV_RETR_EXTERNAL)
while contours:
    (x,y,w,h) = cv.BoundingRect(contours)
    if h > w*1.2 and h > 20:
        cv.Rectangle(colorImg, (x,y), (x+w,y+h), cv.Scalar(0,255,255,255))
    contours = contours.h_next()
编辑:您询问了如何仅绘制具有特定属性的轮廓;其内容如下:


你可能应该展示你的代码…很抱歉,它花了很长时间才发布代码。carnieri下面的回答是我问题的正确答案,但是,我不明白为什么使用cvFindNextContour不起作用。如果有人知道,请让我知道。嘿,它起作用了。我如何检查每个边界框?我只想为contour绘制这些框符合特定尺寸标准的。我看到所有轮廓都有一个边界框。是否可以从一个框架中迭代每个轮廓?谢谢,我接受主问题的答案。谢谢“while contour”和“contour=contour.h_next()”我添加了一个仅绘制具有特定属性的轮廓的示例,就像您在代码中所做的那样。
        cvShowImage("contours",out);
        //cvWaitKey();
    }
    //printf("Box Height: %d , Box Width: %d ,People: %d\n",box.height,box.width,ppl);
    //cvWaitKey(0);
    int coord = sprintf_s(buff,"%d,%d,%d\n",box.width,box.height,ppl);
    file.write(buff,coord);
}
file.close();
cvReleaseImage(&out);
return ppl;
contours = cv.findContours(img, cv.CreateMemStorage(0), mode=cv.CV_RETR_EXTERNAL)
while contours:
    (x,y,w,h) = cv.BoundingRect(contours)
    cv.Rectangle(colorImg, (x,y), (x+w,y+h), cv.Scalar(0,255,255,255))
    contours = contours.h_next()
contours = cv.findContours(img, cv.CreateMemStorage(0), mode=cv.CV_RETR_EXTERNAL)
while contours:
    (x,y,w,h) = cv.BoundingRect(contours)
    if h > w*1.2 and h > 20:
        cv.Rectangle(colorImg, (x,y), (x+w,y+h), cv.Scalar(0,255,255,255))
    contours = contours.h_next()