Ask Your Question
1

How does macthTemplate() deal with scaling?

asked Jul 27 '17

CVLearner17 gravatar image
 matchTemplate(Image, Template, ResImage, CV_TM_SQDIFF);

If size of "Image" changes, matchTemplate() can't find location of "Template" in the "Image".

Should "Template" be exact part of "Image" in order for matchTemplate() to find its location?

Preview: (hide)

3 answers

Sort by » oldest newest most voted
2

answered Jul 27 '17

Raki gravatar image

Take a look at this, it explains how one could make Template Matching scale invariant.

Preview: (hide)

Comments

Thank you very much!

CVLearner17 gravatar imageCVLearner17 (Jul 27 '17)edit
2

answered Jul 27 '17

updated Jul 27 '17

In principle matchTemplate does not incorporate scale invariance. But you can introduce it yourself.

  • Start from your original image
  • Apply a couple of pyrUp and a couple of pyrDown, creating a scale pyramid
  • Now run matchTemplate with a fixed template on all images, be sure to use TM_SQDIFF_NORM <-- the normalized is important here
  • Now for each scale take best match, store it in vector.
  • Then over all best matches in vector take strongest one (so with the smallest difference).

Also about being an exact part of original image: NO it does not. The sample is made that way and confuses people, but in general, in an application the template is NOT related to the image where you apply it.

Good luck!

Preview: (hide)

Comments

1

@StevenPuttemans Thank you. Your answer gave me some hope.

CVLearner17 gravatar imageCVLearner17 (Jul 27 '17)edit
2

answered Jul 27 '17

LBerger gravatar image

updated Jul 27 '17

matchTemplate is not scale invariant. Template in both image must have same size.

You can try https://github.com/Smorodov/LogPolarF...

Preview: (hide)

Comments

@LBerger Thank you. I will try that too.

CVLearner17 gravatar imageCVLearner17 (Jul 27 '17)edit

Question Tools

1 follower

Stats

Asked: Jul 27 '17

Seen: 12,779 times

Last updated: Jul 27 '17