Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching a curve pattern to the edges of an image

I have a target image to be searched for a curve along its edges and a template image that contains the curve. What I need to achieve is to find the best match of the curve in the template image within the target image, and based on the score, to find out whether there is a match or not. That also includes rotation and resizing of the curve. The target image can be the output of a Canny Edge detector if that makes things easier.

I am considering to use OpenCV (by using Python or Processing/Java or if those have limited access to the required functions then by using C) to make things practical and efficient, however could not find out if I can use any functions (or a combination of them) in OpenCV that are useable for doing this job. I have been reading through the OpenCV documentation and thought at first that Contours could do this job, however all the examples show closed shapes as opposed to my case where I need to match a open curve to a part of an edge.

So is there a way to do this either by using OpenCV or with any known code or algorithm that you would suggest?

Here are some images to illustrate the problem:

Template image containing the curve to be searched for

Input image to be searched for the template curve and to be matched to its edges; this can also be an edge-image, the output of a Canny Edge detector rather than the unprocessed input image

Resulting match - includes rotation and resizing

like image 346
ali Avatar asked Jul 30 '12 21:07

ali


1 Answers

My first thought was Generalized Hough Transform. However I don't know any good implementation for that.

I would try SIFT or SURF first on the canny edge image. It usually is used to find 2d areas, not 1d contours, but if you take the minimum bounding box around your contour and use that as the search pattern, it should work.

OpenCV has an implementation for that: Features2D + Homography to find a known object

A problem may be getting a good edge image, those black shapes in the back could be distracting.

Also see this Stackoverflow answer: Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition

like image 171
HugoRune Avatar answered Oct 21 '22 21:10

HugoRune