自动图片点击
网盘链接:https://pan.baidu.com/s/1vW9H8483zP51wdaLrU4z2A?pwd=aini
提取码:aini
代码是用python写的,用的pyinstaller打包的,所以文件比较大(如果有更好的方法请不啬赐教)
Tips
压缩包内容如上,你要做的就是把你需要点击的图片截图下来放进该文件夹,图片命名不能有中文,后缀是.jpg格式(如图片1,2,3)。图片的路径或者本文件夹路径也不可以出现中文。
使用方法
直接点击click.exe文件即可,会自动寻找你的当前电脑页面内容是否含有你想要点击的图片(例图1,2,3),相邻两次寻找之间是间隔5秒。
代码放在了click.py,大家可以进行修改或者直接运行代码也行。
import time
import pyautogui
from PIL import ImageGrab, Image
import pyscreeze
import cv2
import os
# 屏幕缩放系数 mac缩放是2 windows一般是1
screenScale=1
#事先读取按钮截图
jpgs = []
k = 0
for i in os.listdir('./'):
if 'jpg' in i:
pigc = cv2.imread(r"./{}".format(i),cv2.IMREAD_GRAYSCALE)
jpgs.append(pigc)
choice = 1
time_1 = time.time()
while(1):
if time.time() - time_1 > 5:
choice += 1
time_1 = time.time()
target = jpgs[choice%3]
# 先截图
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 ("没找到")