使用opencv或javacv识别图像中具有相同颜色的轮廓? [英] identify contours in a image which are having same color using opencv or javacv?
问题描述
这个问题与我的上一个问题在那个问题中我使用彩色图像作为输入,它通过使用线条颜色来识别,但我想知道如何使用灰度图像识别这种图像。
这是灰度输入图像,必须识别
This question is related to my previous question in that question I used color image as input and it identify by using line color but I like to know how to identify that kind of image using gray-scale image. This is the gray-scale input image and have to identify
我需要识别以下物体的位置(x和y坐标)。
And I need to identify following objects with its positions (x and y coordinates).
请一些人用简单的代码示例来解释这些对象,我需要识别这些对象的连接线(如下图所示)。
Please can some one explain with simple code example to identify those objects and I need to identify connected lines of those objects as well (As shown in following image).
请善待使用简单的代码示例来解释这一点。
Please be kind enough to explain this using simple code example.
推荐答案
解决方案的概念与之前的问题相同 - 使用扩展和侵蚀:
The concept of solution is the same as with previous question - use dilate and erode:
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);
结果:
这篇关于使用opencv或javacv识别图像中具有相同颜色的轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!