Ask Your Question
1

How does macthTemplate() deal with scaling?

asked 2017-07-27 03:08:46 -0600

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?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
2

answered 2017-07-27 06:50:54 -0600

Raki gravatar image

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

edit flag offensive delete link more

Comments

Thank you very much!

CVLearner17 gravatar imageCVLearner17 ( 2017-07-27 11:09:16 -0600 )edit
2

answered 2017-07-27 03:29:54 -0600

updated 2017-07-27 03:30:58 -0600

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!

edit flag offensive delete link more

Comments

1

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

CVLearner17 gravatar imageCVLearner17 ( 2017-07-27 05:06:38 -0600 )edit
2

answered 2017-07-27 03:12:52 -0600

LBerger gravatar image

updated 2017-07-27 03:14:06 -0600

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

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

edit flag offensive delete link more

Comments

@LBerger Thank you. I will try that too.

CVLearner17 gravatar imageCVLearner17 ( 2017-07-27 05:07:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-27 03:08:46 -0600

Seen: 12,117 times

Last updated: Jul 27 '17