7

As you can see in the image, I would like to compare these contours.

contours

I need my OpenCV program to return TRUE when of these contours are compared to each other. They all kind off look the same but as you can see they are not exactly the same.

The result you see here is what I have returned from the function findContours.

So I am looking for the right approach for similarity for these contours.

Any help would be amazing.

Thank you very much in advance.

Wim Vanhenden
  • 841
  • 2
  • 12
  • 18

2 Answers2

7

Take a look at cvMatchShapes() (which used to be call cvMatchContours()).

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
  • Thanks man! I'll get on it right away. I was thinking of using the K Nearest Neigbour method but I'm not sure how to implement it correctly in OpenCV. – Wim Vanhenden Feb 20 '12 at 15:30
  • Adi, can you tell me how to use cvMatchShapes. When I try to run it with contours filled with vector > I am getting: OpenCV Error: Assertion failed. Thanks in advance. – Wim Vanhenden Feb 20 '12 at 22:32
  • Wim, I'm sorry, I've never actually used it. – Adi Shavit Feb 21 '12 at 07:28
6

To use the matchShapes() function you should pass vector<Point>, vector<Point> as arguments. So not contours container as you do, but particular contours from it. Shapes you are trying to compare should be one contour.

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
krzych
  • 2,126
  • 7
  • 31
  • 50