Ask Your Question
0

Opencv exact match

asked 2014-03-05 08:32:26 -0600

iperc gravatar image

updated 2014-03-05 09:11:30 -0600

berak gravatar image

I have two images, and I need to find one image in another.

Source image: link

Need find this image: link

There is a simple python code that finds a match

import cv2
import numpy as np

source = cv2.imread('screen1.jpg')
template = cv2.imread('tpl.jpg')

result = cv2.matchTemplate(source,template,cv2.TM_CCOEFF_NORMED)
y,x = np.unravel_index(result.argmax(), result.shape)
print x,y

It returns coordinates

185 3

But they are wrong, because the image that we are looking for is not available in our image

How to make to return an exact match, and if not found then return false or 0 0

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-03-05 09:58:39 -0600

Guanta gravatar image

Just apply a threshold on results.argmax(), i.e. if it is above a certain threshold then assume you have found a match. Afaik, if the size of the image you are searching is equal in the searched images, then you can even set the threshold to 1.0, otherwise pick a lower one.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-03-05 08:32:26 -0600

Seen: 1,568 times

Last updated: Mar 05 '14