我的第一个python项目
import time
import pyautogui
from PIL import Image
from paddleocr import PaddleOCR
ActOCR = PaddleOCR()
while True:
# 获取指定坐标的截图
def capture_screenshot_at_coordinates(x1, y1, x2, y2):
# 获取整个屏幕的截图
screenshot = pyautogui.screenshot()
# 裁剪出指定坐标范围内的区域
region = screenshot.crop((x1, y1, x2, y2))
return region
# 开始截图
screenshot = capture_screenshot_at_coordinates(110, 320, 240, 400)
screenshot.save('number1.png')
screenshot = capture_screenshot_at_coordinates(320, 320, 410, 400)
screenshot.save('number2.png')
# 文字识别
ocrNum1 = ActOCR.ocr(r'C:\Users\him69\Desktop\projects\xiaoyuankousuan\number1.png')
NumberStr1 = ocrNum1[0][0][1][0]
ocrNum2 = ActOCR.ocr(r'C:\Users\him69\Desktop\projects\xiaoyuankousuan\number2.png')
NumberStr2 = ocrNum2[0][0][1][0]
Number1 = int(NumberStr1)
Number2 = int(NumberStr2)
# 查找模拟器窗口的标题,假设标题为“雷电模拟器”
window = pyautogui.getWindowsWithTitle("雷电模拟器")[0]
x, y, width, height = window.left, window.top, window.width, window.height
# 拖动
def fast_drag(start_x, start_y, end_x, end_y):
pyautogui.moveTo(start_x, start_y)
pyautogui.dragTo(end_x, end_y, duration=0.15) # 可以根据需要调整 duration 的值以控制速度
if Number1 < Number2:
print("<")
fast_drag(x + 250, y + 650, x + 150, y + 750)
fast_drag(x + 150+50, y + 750-50, x + 250+50, y + 850-50)
else:
print(">")
fast_drag(x + 150, y + 650, x + 250, y + 750)
fast_drag(x + 250-50, y + 750-50, x + 150-50, y + 850-50)
print("Number1 is: "+NumberStr1)
print("Number2 is: "+NumberStr2)
time.sleep(0.4)
速度不够快,直接被大学生秒杀了,后面试试抓包
标签:pyautogui,截图,screenshot,Python,50,window,小猿口,import,OCR From: https://www.cnblogs.com/xiins/p/18459047