Ask Your Question

Revision history [back]

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.