按照模拟器位置捕捉截图,使用paddleocr识别数字后比较大小
import pyautogui, time
from paddleocr import PaddleOCR
paddleocr = PaddleOCR(lang='en', show_log=False, use_angle_cls=True)
def capture_screenshot(region=None):
img = pyautogui.screenshot(region=region) # 捕捉屏幕截图指定区域
img.save('temp.png')
res = paddleocr.ocr('temp.png',cls=True)
text = ''
for r in res[0]:
text += r[1][0]
print(f'识别文本: {text}', end=' ')
return text
def cal_result(text1, text2):
num1, num2 = float(text1), float(text2)
ret = '<' if float(num1) < float(num2) else '>'
print(f'判断结果: {ret}')
return ret
def draw_result(result):
pyautogui.moveTo(600, 600) # 鼠标移动到起始位置
if result == '<':
pyautogui.dragTo(550, 650, button='left', duration=0.2)
pyautogui.dragTo(600, 700, button='left', duration=0.1)
else:
pyautogui.dragTo(650, 650, button='left', duration=0.2)
pyautogui.dragTo(600, 700, button='left', duration=0.1)
for i in range(10):
text1 = capture_screenshot(region=(370, 400, 80, 80))
text2 = capture_screenshot(region=(515, 400, 80, 80))
result = cal_result(text1, text2)
draw_result(result)
time.sleep(0.35)
标签:pyautogui,python,text,ret,袁口算,result,paddleocr,ocr
From: https://www.cnblogs.com/wstong2052/p/18522141