0

I am writing a program that will take a screenshot every few seconds then attempt to template match this screenshot with a predetermined template. However, if I were to attempt to do an if statement, how would I write that? How can I determine whether the templateMatch actually succeeded or not?

Source Code:

import cv2 as cv
import time
import pyautogui
import os

template = cv.imread('C:\\Users\\Bran\\Pictures\\ovw_focus_point.jpg',0)
w, h = template.shape[::-1]
while True:
    time.sleep(5)
    sc = pyautogui.screenshot()
    os.remove('C:\\Users\\Bran\\Pictures\\OWSC\\test-1.png')
    sc.save('C:\\Users\\Bran\\Pictures\\OWSC\\test-1.png')
    print('one loop')
    img = cv.imread('C:\\Users\\Bran\\Pictures\\OWSC\\test-1.png',0)
    method = eval('cv.TM_CCOEFF')
    res = cv.matchTemplate(img,template,method)

I'm not sure how to structure my code from this point. I plan to have the program perform a function once there is a successful template match. Hope someone can help!

Bran
  • 19
  • 6
  • Check if this helps: https://stackoverflow.com/questions/9709631/how-do-i-use-opencv-matchtemplate – iGian Mar 26 '20 at 15:36
  • @iGian this does help! I have a question though, it says in the first answer to the question that you need to set a threshold for the minVal, how would I do that? I am just looking for a single match – Bran Mar 26 '20 at 23:00

0 Answers0