首相片帖子已经重复的太多了,我试一下感觉还是很好用的,我就是记录一下
这篇帖子可以直接制作出很多自动点击的工具,甚至是游戏物理辅助工具(因为我就在用)!
视频展示
库 |
安装 |
作用 |
pillow |
pip install pillow |
加载图片 |
pyscreeze |
pip install pyscreeze |
截屏 |
pyautogui |
pip install pyautogui |
控制鼠标或键盘 |
opencv-python |
pip install opencv-python==4.3.0.38 |
识别匹配图片 |
import time
from time import sleep
import pyautogui
import pyperclip
from PIL import ImageGrab, Image
import pyscreeze
import cv2
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))
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 ("没找到")
最后感谢原帖,帮我解决了一个大问题:点我查看原帖
希望对大家有帮助
致力于办公自动化的小小程序员一枚
致力于写出清楚的博客
都看到这了,关注+点赞+收藏=不迷路!