2

I would like to use matchShapes() function to find an object inside a query image.

Let's say I have a model image of a book, i want to extract its shape and then try to find this book (its shape) inside another image.

I have googled a lot but couldn't find any real example on how to use matchShapes to achive this. The documentation lacks. Can someoen make a little example in C++ ?

Thanks a lot! (Note I know I can use SIFT/ORB etc, but i want to use matchShapes())

1 Answers1

3

Step 1: Detect contour of book and store it in vector<Point>.

Step 2: Detect contours on another image.

Step 3: Iterate over detected contours and match shape detected in Step 1 with each contour detected on another image. You have detected vector<vector<Point> > contours. Iterating over them you pass model vector<Point> from Step 1 and vector<Point> from contours to matchShape() function. See my answer here how to use matchShape() function.

Note that book must have the same shape on another image as on model image. It can only be rotated, displaced or scaled.

Community
  • 1
  • 1
krzych
  • 2,126
  • 7
  • 31
  • 50
  • Yes and no. You could use OpenCV findContour or for example write your own contours extracting function let's say from Canny output. As documentation say input can be contour or grayscale image, the matchShapes() function bases on Hu invariant moments. So you are not strict to use it with contour. But in your case and most cases it's used with contours. – krzych Jul 31 '12 at 18:11