Ask Your Question
0

Finding simple tetris like shapes

asked 2014-08-28 01:35:19 -0500

Hi all,

I have images like image description and image description, and I want to find these small images in simple black and white larger image like the following:

image description

What classes should I look into or a sample that can help me do this. I would need the pixel locations where the smaller shapes were found and a sort of a percentage to which the match was successful, like was it 80% similar etc.

Thanks.

ps: I'm coding in visual studio 2012 c#.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-08-28 01:56:40 -0500

A first shot would be template matching: http://docs.opencv.org/doc/tutorials/imgproc/histograms/template_matching/template_matching.html

This function moves the smaller image to all possible positions on the larger one and computes a matching score. A good scoring function could be CV_TM_CCORR as it's basically an and-operation. I don't have the time to try it myself, but I think this should work: Apply matchTemplate with one of your templates and the larger image using CV_TM_CCORR as metric and 8-bit (CV_8UC1) image. To compute your final score, you count the number of white pixels in your template image using countNonZero. If you have N white pixels, your maximal score at the perfect match-location is 255255N. Normalize your score-image returned from matchTemplate (via normalize) and look for values at or close to 0.

Small drawback: If you apply this on a completely white image, every position will be a perfect match, but I hope that this is at least a starting point.

Other drawback: This won't work if you want to search for rotated templates.

Second strategy: use HoughLinesP to find all lines, compute the intersections and apply some matching to the line segments.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-08-28 01:35:19 -0500

Seen: 220 times

Last updated: Aug 28 '14