10

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

ali
  • 381
  • 2
  • 12

1 Answers1

2

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

Community
  • 1
  • 1
HugoRune
  • 13,157
  • 7
  • 69
  • 144
  • Thanks, i will try these and come back here to give info about my results or findings. – ali Aug 03 '12 at 13:59
  • 1
    Any luck, Ali? See also this question, which references yours: http://stackoverflow.com/questions/14530790/image-processing-match-curves-from-one-image-to-another – Rethunk Jan 26 '13 at 18:42
  • Thanks Rehunk, haven't seen your comment up until now; long time... I had no real solution, but a partial one that did the work more and less back then; slow and w/o rotations: I used simple correlation matching by resizing the template to different sizes, but not directly with the curve on the image, but on a color coded edge image where each edge point had a corresponding color for its slope, likewise the template curve was color coded based on the slope of the curve on each point. Then I compared those colors by correlation and the results were ok for a limited/practical solution... – ali Jul 15 '14 at 16:28