Reputation: 503
Assuming I have a template image and searching for a match in a video,what is the measure to be looked for ?
From OpenCV tutorial here 1.loc = np.where( res >= threshold) gives me numpy array.How to infer it on a scale of 1-100,where 100 refers to exact match and 80 refers to 80% match and so on. 2.I am not clear on min,max values ..what does rectangle coordinates denote? # Apply template Matching res = cv2.matchTemplate(img,template,method) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
Upvotes: 0
Views: 1374
Reputation: 576
I'm not too familiar with Python, but I have worked with template matching and OpenCV.
Performing a template match produces a results matrix - called res
in your example.
Depending on the template matching method used, the brightest/darkest (max/min) points on this result matrix are your best matches.
In your example the method cv2.TM_SQDIFF_NORMED
is used which will normalise the result matrix values between 0 and 1.
You can then iterate over your result matrix points and only store those points which pass a certain threshold, in the example they use 0.8 which is equivalent to an 80% match.
The last step involves marking each match onto the drawing by using the rectangle drawing function which works as follows:
Rectangle(img, pt1, pt2, color, thickness=1, lineType=8, shift=0)
img
- image matrix, the picture you want to draw onpt1
- Top left point of the rectangle (x,y)pt2
- Bottom right point of the rectangle (x,y)color
- Line colour (BGR format)I answered a similar question here and provided an example that might be of some help to you too.
Upvotes: 1