2021-10-18

# -*- 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)

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

推荐阅读更多精彩内容

  • 1、安装模块:在Windows 上,不需要安装其他模块。 在OS X 上,运行sudo pip3 install...
    SkTj阅读 1,386评论 1 7
  • 最近微信“拍一拍”火遍了各大微信群,并迅速占据了热搜话题榜。于是我突发奇想,决定用pyhton自动实现微信“拍一拍...
    测试汪大牛阅读 208评论 0 0
  • 今日内容 : 破解极验滑动验证 '''破解极验滑动验证破解极验滑动验证博客园登录url: https://acc...
    Aidann阅读 290评论 0 0
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 6,122评论 0 4
  • 公元:2019年11月28日19时42分农历:二零一九年 十一月 初三日 戌时干支:己亥乙亥己巳甲戌当月节气:立冬...
    石放阅读 6,934评论 0 2