Ask Your Question
0

template matching in multiple images

asked 2013-03-30 01:29:55 -0600

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 ???

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-03-30 07:25:29 -0600

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));
edit flag offensive delete link more

Comments

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

Aditya gravatar imageAditya ( 2013-04-02 01:42:38 -0600 )edit

Question Tools

Stats

Asked: 2013-03-30 01:29:55 -0600

Seen: 2,636 times

Last updated: Mar 30 '13