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
OpenCV连接组件的输出 我想复制一个例子,关于连接组件,发现代码不再在线,我想使用C++ API。_C++_Opencv_Contour - Fatal编程技术网

OpenCV连接组件的输出 我想复制一个例子,关于连接组件,发现代码不再在线,我想使用C++ API。

OpenCV连接组件的输出 我想复制一个例子,关于连接组件,发现代码不再在线,我想使用C++ API。,c++,opencv,contour,C++,Opencv,Contour,我使用了以下调用来查找计数器: 其中,通过对文章中提出的图像进行阈值化获得img: 预期产出为: 从CV_RETR_CCOMP的描述中,我希望有6个顶级轮廓,对应于结果图像的6种颜色 文档中说连接的组件是 在顶层,孔是连接组件CC的子级 然而,通过对层次结构的探索,我可以看到前3个等高线0、1、3既没有父等高线,也没有子等高线。它们对应于“a”字母中的孔。其他轮廓位于层次中,请参见末尾的转储。轮廓3是包含所有图像的顶级CC。其他轮廓是预期CC的外部轮廓 Contour 0: next: 1,

我使用了以下调用来查找计数器:

其中,通过对文章中提出的图像进行阈值化获得img:

预期产出为:

从CV_RETR_CCOMP的描述中,我希望有6个顶级轮廓,对应于结果图像的6种颜色

文档中说连接的组件是 在顶层,孔是连接组件CC的子级

然而,通过对层次结构的探索,我可以看到前3个等高线0、1、3既没有父等高线,也没有子等高线。它们对应于“a”字母中的孔。其他轮廓位于层次中,请参见末尾的转储。轮廓3是包含所有图像的顶级CC。其他轮廓是预期CC的外部轮廓

Contour 0: next: 1,  previous: -1,  child: -1,  parent: -1,  size: 4
Contour 1: next: 2,  previous: 0,  child: -1,  parent: -1,  size: 4
Contour 2: next: 3,  previous: 1,  child: -1,  parent: -1,  size: 4
Contour 3: next: -1,  previous: 2,  child: 4,  parent: -1,  size: 4
Contour 4: next: 5,  previous: -1,  child: -1,  parent: 3,  size: 121
Contour 5: next: 6,  previous: 4,  child: -1,  parent: 3,  size: 80
Contour 6: next: 7,  previous: 5,  child: -1,  parent: 3,  size: 18
Contour 7: next: 8,  previous: 6,  child: -1,  parent: 3,  size: 18
Contour 8: next: 9,  previous: 7,  child: -1,  parent: 3,  size: 18
Contour 9: next: -1,  previous: 8,  child: -1,  parent: 3,  size: 8
我已经用OpenCV 2.2和2.3.1测试了代码。 我用一个简单的图像测试了一个带孔的圆,得到了相同的结果3个轮廓:0是孔,1是顶层,2是外轮廓


有人能解释一下这与CV_RETR_CCOMP的文件有什么关系吗

我的问题很接近SSteve的评论。嗯,CV_RETR_树的输出似乎更接近期望的输出。第一个轮廓是全局轮廓,它的子对象是CC的外部轮廓。这些轮廓的子对象是孔。但是它不能正确处理CC内孔。好的,我理解我的问题。。。我被输入的视觉外观误导了。对于findContours,像素的对象必须在255处显示为白色,0处的孔显示为黑色。所以我需要使用输入图像的求反。
Contour 0: next: 1,  previous: -1,  child: -1,  parent: -1,  size: 4
Contour 1: next: 2,  previous: 0,  child: -1,  parent: -1,  size: 4
Contour 2: next: 3,  previous: 1,  child: -1,  parent: -1,  size: 4
Contour 3: next: -1,  previous: 2,  child: 4,  parent: -1,  size: 4
Contour 4: next: 5,  previous: -1,  child: -1,  parent: 3,  size: 121
Contour 5: next: 6,  previous: 4,  child: -1,  parent: 3,  size: 80
Contour 6: next: 7,  previous: 5,  child: -1,  parent: 3,  size: 18
Contour 7: next: 8,  previous: 6,  child: -1,  parent: 3,  size: 18
Contour 8: next: 9,  previous: 7,  child: -1,  parent: 3,  size: 18
Contour 9: next: -1,  previous: 8,  child: -1,  parent: 3,  size: 8