pyautogui+opencv

2023-03-06  本文已影响0人  我和我的火柴

给自己一个Note 为了玩自动化必须要学点OpenCV

import pyautogui as pg
from time import sleep
import cv2 as cv


sleep(3)

def findImg(tmpImg):
    img = pg.screenshot()
    img.save("./images/shot.png")
    shot = cv.imread("./images/shot.png")
    template = cv.imread(tmpImg)
    result = cv.matchTemplate(shot,template,cv.TM_CCOEFF_NORMED) #标准匹配方式
    pos_start = cv.minMaxLoc(result)[3]
    x = int(pos_start[0]) + int(template.shape[1]/2)
    y = int(pos_start[1]) + int(template.shape[0]/2)
    pg.moveTo(x,y,duration=1)

findImg('./images/word.png')
findImg('./images/HBX.png')
findImg('./images/chrome.png')
pg.doubleClick()

sleep(5)

pg.hotkey("win","shift","q")

pg.alert("脚本运行完毕")


上一篇 下一篇

猜你喜欢

热点阅读