美文网首页
2021-10-18

2021-10-18

作者: ducksoul | 来源:发表于2021-10-18 13:29 被阅读0次

    # -*- coding:utf-8 -*-

    import time

    import random

    import aircvas ac

    import pyautogui

    def matchImg(imgsrc, imgobj, confidence=0.9):# imgsrc=原始图像,imgobj=待查找的图片,confidence=设置匹配系数

        imsrc = ac.imread(imgsrc)

    imobj = ac.imread(imgobj)

    match_result = ac.find_template(imsrc, imobj, confidence)

    if match_resultis not None:

    match_result['shape'] = (imsrc.shape[1], imsrc.shape[0])# 0为高,1为宽

            left = match_result['rectangle'][0][1]

    right = match_result['rectangle'][3][1]

    top = match_result['rectangle'][0][0]

    buttom = match_result['rectangle'][3][0]

    pyautogui.moveTo(top, left)

    time.sleep(2)

    pyautogui.moveTo(top, right)

    time.sleep(2)

    pyautogui.moveTo(buttom, left)

    time.sleep(2)

    pyautogui.moveTo(buttom, right)

    time.sleep(2)

    pyautogui.moveTo(random.randint(top,buttom), random.randint(left,right))

    return match_result

    if __name__ =='__main__':

    p = matchImg(r"D:\code\testpic\desktop.png",

                    r"D:\code\testpic\code.png")

    print(p)

    相关文章

      网友评论

          本文标题:2021-10-18

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