How to identify contour which are not directly separated from each other?

早过忘川 提交于 2019-12-04 11:19:57

You have to use fact, that red component of each square equals 255, and do the threshold. Here's what I've done:

  1. Do a red color segmentation:

  2. Do dilatation (to remove holes):

  3. (Optional) Do a check if each contour is a square.

Code:

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!