美文网首页
pyautogui+opencv

pyautogui+opencv

作者: 我和我的火柴 | 来源:发表于2023-03-06 00:50 被阅读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("脚本运行完毕")
    
    
    

    相关文章

      网友评论

          本文标题:pyautogui+opencv

          本文链接:https://www.haomeiwen.com/subject/arapldtx.html