Template matching giving incorrect location

asked 2015-04-27 17:02:01 -0600

215 gravatar image

updated 2018-12-27 20:30:42 -0600

When i perform the openCV template matching, i for some reason get my min location to be at the upper left corner, and my max location to be at the upper right corner, which is not where my template is.. I don't why i doesn't perform like that..

it implemented as such.

The full code can be viewed on my github. https://github.com/Keerthikan/PTU-Fac...

The image is a gray image, and it doesn't matter which method i use.. The result is always the same.. what am I doing wrong?

Here is some test images http://imgur.com/2iooqbIhttp://imgur.com/2iooqbI

edit retag flag offensive close merge delete

Comments

3

It would be better to understand your issue if you post some sample images and results.

Spark gravatar imageSpark ( 2015-04-28 00:44:24 -0600 )edit

http://imgur.com/2iooqbI... The circle in the source shows the maxLoc.

215 gravatar image215 ( 2015-04-28 03:06:23 -0600 )edit

It seems that you have a list of points and you compute matchTemplate on a small window around the location of each point. I think that the common approach to perform template matching when I see your image is to directly use matchTemplate with the whole template image like in this tutorial.

Eduardo gravatar imageEduardo ( 2015-04-28 04:24:39 -0600 )edit

I will add the full code now.. I changed somethings and made it move to some other location.. But it doesn't work as i had expected, i was hoping that the maxLoc would be the center position of where the patch fits.. I don't understand why it says that it is corner that has max location.

215 gravatar image215 ( 2015-04-28 05:28:39 -0600 )edit

"I don't understand why it says that it is corner that has max location."

You should look at this: If image is WxH and templ is wxh , then result is (W-w+1)x(H-h+1). It is just a question of coordinates change between the result image size and the input image size.

Eduardo gravatar imageEduardo ( 2015-04-28 07:16:35 -0600 )edit

But it doesn't say what that coordinate is... I mean is it the center of the face, top, tl, br? It still doesn't place the circle where i expect it be.. which the center of where the template matches.m

215 gravatar image215 ( 2015-04-28 11:02:50 -0600 )edit