当前位置: 首页 > news >正文

小猿口算脚本

实现原理:安卓adb截图传到电脑,然后用python裁剪获得两张数字图片,使用ddddocr识别数字,比较大小,再用adb命令模拟安卓手势实现><

import os
import ddddocr
from time import sleep
from PIL import Imagedef take_screenshot(path):"""从设备截取屏幕并保存到指定路径。"""os.system(f'adb shell screencap -p > {path}')# 读取截取的屏幕截图并替换行结束符with open(path, 'rb') as f:return f.read().replace(b'\r\n', b'\n')def process_image(image_path, crop_area):"""打开图片,裁剪并返回裁剪后的图片。"""with Image.open(image_path) as img:return img.crop(crop_area)def extract_text(img):"""提取图片中的文本。"""with open(img, 'rb') as f:img_bytes = f.read()res = ocr.classification(img_bytes)return res.replace(' ', '').replace('\n', '')def compare_numbers(x, y):"""比较两个数字并相应地执行滑动操作。"""try:x_int, y_int = int(x), int(y)if x_int > y_int:print(f"{x} > {y}")os.system("adb shell input swipe 450 1800 850 1900 1")os.system("adb shell input swipe 850 1900 450 2000 1")else:print(f"{x} < {y}")os.system("adb shell input swipe 850 1800 450 1900 1")os.system("adb shell input swipe 450 1900 850 2000 1")except ValueError:print("数字格式无效。")def main():"""主程序逻辑。"""screenshot_path = 'screenshot.png'# 截取屏幕并保存screenshot = take_screenshot(screenshot_path)with open(screenshot_path, 'wb') as f:f.write(screenshot)# 定义裁剪区域(左,上,右,下)分别是两个数字在图片中的区域坐标crop_areas = [(330, 720, 530, 880),(730, 720, 930, 880)]cropped_images = []for i, crop_area in enumerate(crop_areas, start=1):cropped_image = process_image(screenshot_path, crop_area)cropped_image_path = f"screenshot{i}.png"cropped_image.save(cropped_image_path)cropped_images.append(cropped_image_path)# 从裁剪后的图片中提取文本texts = [extract_text(image) for image in cropped_images]# 比较提取的数字compare_numbers(texts[0], texts[1])if __name__ == '__main__':ocr = ddddocr.DdddOcr(show_ad=False)while True:main()sleep(0.2)

http://www.lryc.cn/news/457648.html

相关文章:

  • 从 Reno TCP 到 Scalable TCP,HighSpeed TCP
  • 使用Java调用OpenAI API并解析响应:详细教程
  • 深入学习并发编程中的 synchronized
  • AMD R9-9950X相比较I9-14900K有哪些提升
  • 计算机毕业设计 基于Python的个性化旅游线路推荐系统的设计与实现 Python+Django+Vue 前后端分离 附源码 讲解 文档
  • 总结:Flink之DataStream各API介绍
  • 设计一个日志管理系统,支持多级别日志记录
  • Javascript动态规划算法
  • Java 循环里怎么删除元素才安全
  • LabVIEW晶体振荡器自动化测试系统
  • 3.6.xx版本SpringBoot创建基于Swagger接口文档
  • Oracle 12201非PDBS模式单机部署(静默安装)
  • Python 源码编译安装详解:跨平台指南及完整步骤解析
  • MQTT vs HTTP:谁更适合物联网?
  • 小北的技术博客:探索华为昇腾CANN训练营与AI技术创新——Ascend C算子开发能力认证考试(初级)
  • 鸿蒙next开发者第一课02.DevEcoStudio的使用-习题
  • 【vue】监听table水平滚动条切换tab后还原位置
  • C#使用PdfSharp生成PDF文件实例详解
  • 【软件系统架构设计师-案例-1】架构风格
  • 神经网络整体架构
  • 山西农业大学20241010
  • 小北的技术博客:探索华为昇腾CANN训练营与AI技术创新——Ascend C算子开发能力认证考试(中级)
  • Docker极速入门一文通
  • Unity网络开发基础 —— 实践小项目
  • 四、Spring Boot集成Spring Security之认证流程
  • Chromium 中chrome.bookmarks扩展接口c++实现
  • 编程思想:编程范式:响应式编程
  • Leetcode 颜色分类
  • ssh连接阿里云长连接
  • 栈的C实现