pyautogui+opencv

给自己一个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("脚本运行完毕")


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容