自动图片点击——机械式刷课必备

这是一个使用Python编写的自动图片点击工具,通过pyautogui和OpenCV库来识别并点击屏幕上指定的图片。用户需要将待点击的图片放入文件夹中,命名为数字.jpg格式,无中文名。程序每5秒检查一次屏幕,寻找并点击匹配的图片。
摘要由CSDN通过智能技术生成

自动图片点击

网盘链接: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 ("没找到")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值