First time here? Check out the FAQ!

Ask Your Question
0

template matching in multiple images

asked Mar 30 '13

Aditya gravatar image

I am using template matching to find the source in template image. I want to check the source in multiple images and find the best available match. What template matching does is, it returns the closest available match. So even if the source ain't there in template, the application returns something as the match. and i am getting (say) 5 outputs for 5 template images, one for each. Can anybody tell me how can i see the results of the matches before printing them, so that i can select the best match and select it as the result ???

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Mar 30 '13

Guanta gravatar image

I guess you have read the documentation for matchTemplate: http://docs.opencv.org/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#cv.MatchTemplate . If not please read it first.

So with matchTemplate you get a kinda probability-map and with minMaxLoc you get the location where it is the most probable that your template is located in the probability map (and thus also in your real image). So having the 5 maximas (or minimas depending on your template-matching method) which are pointing to the most probable locations in each image you can now just compare them. The heighest (lowest) value is the most probable match. The location of it relates to the top left corner of the template, i.e. the match you can then get by:

Mat match = image(cv::Rect(highest_maxLoc.x, highest_maxLoc.y, templateMat.cols, templateMat.rows));
Preview: (hide)

Comments

Thanx. It helped. Cant believe people still want to help others :)

Aditya gravatar imageAditya (Apr 2 '13)edit

Question Tools

Stats

Asked: Mar 30 '13

Seen: 2,797 times

Last updated: Mar 30 '13