How to define a circuit that is not separate from each other?

Please explain how to determine the square shape of contours that are not exactly divided with each other. For example, I need to identify the number of squares in the image below and the x, y coordinates of their edges. I am trying to get through this question, but it did not work for me.

enter image description here

So please, someone explain this using a simple code example.

This is an image that I can generate, you can explain how to identify the above squares in this image.

enter image description here

So, be kind enough to explain this.

+4
source share
1 answer

You must use the fact that the red component of each square is 255 and fulfills the threshold. Here is what I did:

  • Segment the red color: enter image description here

  • Dilate (to remove holes): enter image description here

  • (Optional) Verify that each contour corresponds to 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); 
+5
source

All Articles