No products are associated with this question.
Is your goal only to detect square in this picture?
If so, you don't need to do shape recognition, etc.
You just need to perform some morphologichal operations only.
I = imread('3617ca70.png'); Ibw = ~im2bw(I,graythresh(I));
Ifill = imfill(Ibw,'holes'); Iarea = bwareaopen(Ifill,100); Ifinal = bwlabel(Iarea);
stat = regionprops(Ifinal,'boundingbox'); imshow(I); hold on; for cnt = 1 : numel(stat) bb = stat(cnt).BoundingBox; rectangle('position',bb,'edgecolor','r','linewidth',2); end
And the result :
Is this what you need?
Those squares are very well defined.
In theory you'll have a mask of the boxes.
I just thought of an alternative idea. Instead of detecting a square, you should register the image (filled form) of interest with the raw image. Then, since you know the coordinates of each square, you can just check the pixels at those coordinates for the white/black values.