如何识别不直接相互分离的轮廓? [英] How to identify contour which are not directly separated from each other?
问题描述
请有人解释如何识别彼此不完全分开的轮廓的方形。例如,我需要识别下面图像中的方块数和它们边缘的x,y坐标。我尝试通过这个问题,但它对我不起作用。
Please can some one explain how to identify square shape of contours which are not exactly separated each other. For example I need to identify the number of squares in below image and the x,y coordinates of their edges. I try to go through this question but it didn't work for me.
所以请使用简单的代码示例来解释一下。
So please can some one explain this using simple code example.
这是我可以生成的图像,请您解释一下识别此图片中的上方方块。
This is the image that I can generated can you please explain how to identify above squares in this image.
所以请善意解释一下。
推荐答案
你必须使用事实,每个方块的红色分量等于255,并做阈值。这就是我所做的:
You have to use fact, that red component of each square equals 255, and do the threshold. Here's what I've done:
-
进行红色分割:
Do a red color segmentation:
做扩张(去除洞):
Do dilatation (to remove holes):
代码:
Mat src = imread("input.png"), red;
extractChannel(src, red, 2);
threshold(red, red, 254, 255, THRESH_BINARY);
Mat element = getStructuringElement(MORPH_RECT, Size( 2, 2 ), Point( 1, 1 ));
dilate(red, red, element);
这篇关于如何识别不直接相互分离的轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!