Answer the question
In order to leave comments, you need to log in
How to use cv2.matchTemplate without saving the source to disk?
We have the following code. actions. We make a screen. looking for "zzz.png" on the screen. If found, we display the coordinates.
But if you try to send a screenshot of a variable (the code below), then we get the error "Expected Ptr for argument 'image'", if I understand correctly, it swears that there is a mandatory argument that the matchTemplate function is waiting for, and which is allegedly not specified ...
def chek():
img = ImageGrab.grab()
template = cv2.imread("zzz.png")
res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF_NORMED)
min_v, max_v, min_pt, max_pt = cv2.minMaxLoc(res)
threshold=0.98
loc = np.where( res >= threshold)
# print(str(x)+' '+str(y))
coord=1
for pt in zip(*loc[:: -1]):
x,y=pt
print('coord = '+str(coord))
print(x)
print(y)
coord=coord+1
img1 = ImageGrab.grab()
img.save('test.png')
img = cv2.imread("test.png")
template = cv2.imread("zzz.png")
res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF_NORMED)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question