使用opencv或javacv识别图像中具有相同颜色的轮廓?

时间:2012-08-23 08:59:35

标签: java opencv javacv

这个问题与我在previous question的问题有关,我使用彩色图像作为输入,并使用线条颜色进行识别,但我想知道如何使用灰度图像识别这种图像。 这是灰度输入图像,必须识别

enter image description here

我需要用它的位置(x和y坐标)来识别以下物体。

enter image description here

有些人可以用简单的代码示例来解释这些对象,我也需要识别这些对象的连接线(如下图所示)。

enter image description here

请使用简单的代码示例来解释这一点。

1 个答案:

答案 0 :(得分:1)

解决方案的概念与之前的问题相同 - 使用扩张和侵蚀:

Mat src = imread("input.jpg"), tmp;

cvtColor(src, tmp, CV_BGR2GRAY);
threshold(tmp, tmp, 200, 255, THRESH_OTSU);

Mat element = getStructuringElement(MORPH_RECT, Size(3, 3), Point(1, 1));
dilate(tmp, tmp, element);
erode(tmp, tmp, element);

结果:

enter image description here

相关问题