当前位置:   article > 正文

python识别图标并点击_python找图点击

python找图点击

首相片帖子已经重复的太多了,我试一下感觉还是很好用的,我就是记录一下

这篇帖子可以直接制作出很多自动点击的工具,甚至是游戏物理辅助工具(因为我就在用)!

视频展示

在这里插入图片描述

安装作用
pillowpip install pillow 加载图片
pyscreezepip install pyscreeze截屏
pyautoguipip install pyautogui 控制鼠标或键盘
opencv-pythonpip install opencv-python==4.3.0.38识别匹配图片
import time
import pyautogui
import pyscreeze
import cv2

# 屏幕缩放系数 mac缩放是2 windows一般是1
screenScale=1

#事先读取按钮截图
target= cv2.imread(r"./image/ssk.png",cv2.IMREAD_GRAYSCALE)
# 先截图
screenshot=pyscreeze.screenshot('my_screenshot.png')
# 读取图片 灰色会快
temp = cv2.imread(r'my_screenshot.png',cv2.IMREAD_GRAYSCALE)

theight, twidth = target.shape[:2]
tempheight, tempwidth = temp.shape[:2]
print("目标图宽高:"+str(twidth)+"-"+str(theight))
print("模板图宽高:"+str(tempwidth)+"-"+str(tempheight))
# 先缩放屏幕截图 INTER_LINEAR INTER_AREA
scaleTemp=cv2.resize(temp, (int(tempwidth / screenScale), int(tempheight / screenScale)))
stempheight, stempwidth = scaleTemp.shape[:2]
print("缩放后模板图宽高:"+str(stempwidth)+"-"+str(stempheight))
# 匹配图片
res = cv2.matchTemplate(scaleTemp, target, cv2.TM_CCOEFF_NORMED)
mn_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
if(max_val>=0.9):
    # 计算出中心点
    top_left = max_loc
    bottom_right = (top_left[0] + twidth, top_left[1] + theight)
    tagHalfW=int(twidth/2)
    tagHalfH=int(theight/2)
    tagCenterX=top_left[0]+tagHalfW
    tagCenterY=top_left[1]+tagHalfH
    #左键点击屏幕上的这个位置
    pyautogui.click(tagCenterX,tagCenterY,button='left') # 点击


else:
    print ("没找到")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

最后感谢原帖,帮我解决了一个大问题:点我查看原帖

希望对大家有帮助

致力于办公自动化的小小程序员一枚

致力于写出清楚的博客

都看到这了,关注+点赞+收藏=不迷路!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/787604
推荐阅读
相关标签
  

闽ICP备14008679号