Detecting a lego base plate in an image

I want my code to find the corners of a square lego plate in an image like the attached one.

I also want to find its dimensions, i.e. the number of "blops" in both dimensions (48x48 in the attached image).

I am currently looking at detecting individual "blops" and the result is still pretty good: a combination of blur, adaptiveThreshold, findContours and region-based selection finds the outlines displayed in the second attached image (color is random).

Now I am looking for an algorithm to find the "grid" represented by these contours (or their midpoints), but I am missing google fu. Any ideas?

(Suggestions for different approaches are also very welcome.)

(The sample image shows bricks placed in corners - the algorithm could expect this if that helps.)

(The sample image has a rather wild background. I would rather handle this if possible.)

Update July 8, 2016. I am trying to write an algorithm that looks for bands of adjacent contours that form lines. Algo should be able to find several of them, and from this derive the shape of the whole plate, even from the point of view. Will be updated if it works ...

December 2017 update: the algorithm described above worked, although it was too unpredictable. I also have problems with perspective (adding a β€œthick” brick made of brick changes the surface) and color recognition (shadows, camera features, etc.). At the moment, this work is suspended. If I renewed it, I will try with fixed camera positions immediately above the plate and matched signals.

Lego platform

The contours found in the Lego plate image

+5
source share

All Articles