import pyautogui
import cv2
def getBigImg():
savedPath = "/Users/mac/Desktop/screenshot.png"
pyautogui.screenshot().save(savedPath)
bigImg = cv2.imread(savedPath)
return bigImg
def get_xy(imgFilePath, bigImg):
img_terminal = cv2.imread(imgFilePath)
height, width, channel = img_terminal.shape
result = cv2.matchTemplate(bigImg, img_terminal, cv2.TM_SQDIFF_NORMED)
upper_left = cv2.minMaxLoc(result)[2]
lower_right = (upper_left[0] + width, upper_left[1] + height)
avg = (
int((upper_left[0] + lower_right[0]) / 2),
int((upper_left[1] + lower_right[1]) / 2),
)
return avg
def clickSmallImg(smallImgFilePath):
avg = get_xy(smallImgFilePath, getBigImg())
pyautogui.click(*avg, button="left")
smallImgFilePath = "/Users/mac/Desktop/Snipaste_2023-10-14_16-03-53.png"
clickSmallImg(smallImgFilePath)