{"id":13672540,"url":"https://github.com/Skyexu/TopSup","last_synced_at":"2025-04-27T22:32:22.729Z","repository":{"id":185828829,"uuid":"116683314","full_name":"Skyexu/TopSup","owner":"Skyexu","description":"答题辅助决策：头号英雄等答题类游戏","archived":false,"fork":false,"pushed_at":"2019-12-15T13:07:43.000Z","size":4977,"stargazers_count":1317,"open_issues_count":108,"forks_count":352,"subscribers_count":61,"default_branch":"master","last_synced_at":"2025-04-08T19:22:06.479Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.jianshu.com/p/dc828c4b901d","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Skyexu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-01-08T13:57:07.000Z","updated_at":"2025-01-02T14:04:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"09be8b0b-649d-4bdb-a1f3-55222a5c16f7","html_url":"https://github.com/Skyexu/TopSup","commit_stats":null,"previous_names":["skyexu/topsup"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyexu%2FTopSup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyexu%2FTopSup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyexu%2FTopSup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyexu%2FTopSup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Skyexu","download_url":"https://codeload.github.com/Skyexu/TopSup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219601,"owners_count":21554444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:38.665Z","updated_at":"2025-04-27T22:32:21.977Z","avatar_url":"https://github.com/Skyexu.png","language":"Python","readme":"\n# 答题辅助\n这两天冲顶大会之类的直播答题 APP 突然火了起来，萌生了使用截图，文字识别，搜索来玩答题的想法。\n\n因为截图时间、搜索结果等限制，使用文字识别搜索，能提供的辅助作用有限。 \n\n\n\n\n**非常感谢关注，欢迎大家 PR 更多有趣的想法和优化。**\n\n![](/resources/screenshot.png)\n\n**目录**\n\n- [答题辅助](#答题辅助)\n  - [更新日志](#更新日志)\n  - [具体做法](#具体做法)\n  - [结果判断方式](#结果判断方式)\n  - [使用步骤 (谷歌 Tesseract)](#使用步骤-谷歌-tesseract)\n  - [使用步骤 (百度 OCR，推荐方式)](#使用步骤-百度-ocr，推荐方式)\n- [其它](#其它)\n- [总结](#总结)\n- [Next](#next)\n\n\n\n## 更新日志\n\n- 2018.01.14\n  - 文字识别方法集成 baidu ocr ，相对来说识别快 ，可在运行代码中选择想要用的 ocr 方式\n  - 题目和选项一次截取识别\n  - 将需要配置的参数统一调整到 `config/configure.conf`中\n- 2018.01.12\n  - 修复 windows 命令行颜色乱码，处理一些识别错误\n- 2018.01.11\n  - 修复搜索可能的乱码等一些问题，多线程加快执行\n- 2018.01.10\n  - 增加循环，无需重复加载，优化逻辑和显示 来自 [issue #7](https://github.com/Skyexu/TopSup/issues/7)。增加部分手机截图设置\n  - 增加了截图传输效率，修改了识别参数，对图像进行灰度转化，去干扰，增加了识别准确率。结果判断使用了三种方式，对不同问题可以参考不同结果。\n\n\n\n\n\n## 具体做法\n\n1. ADB 获取手机截屏\n```\nadb shell screencap -p /sdcard/screenshot.png\nadb pull /sdcard/screenshot.png .\n```\n2. OCR 识别题目与选项文字   \n\n  ![](/resources/cut.png)\n\n  ​\n  两个方法：\n\n  - 谷歌 [Tesseract](https://github.com/madmaze/pytesseract) ，安装软件即可，不同电脑配置运行效率不同\n  - [百度 OCR](https://cloud.baidu.com/product/ocr) ，需要注册百度 API，每天调用次数有限\n\n3. 搜索判断\n\n## 结果判断方式\n\n1. 直接打开浏览器搜索问题\n  ![](./resources/result.png)\n2. 题目+每个选项都通过搜索引擎搜索，从网页代码中提取搜索结果计数\n3. 只用题目进行搜索，统计结果页面代码中包含选项的词频\n\n以下为两个示例结果\n\n![](./resources/result2.png)\n\n![](./resources/result3.png)\n\n参考了 [I Hacked HQ Trivia But Here’s How They Can Stop Me](https://hackernoon.com/i-hacked-hq-trivia-but-heres-how-they-can-stop-me-68750ed16365)\n\n## 使用步骤 (谷歌 Tesseract)\n### Android\n\n#### 1. 安装 ADB\n\n**windows**\n\n下载地址：https://adb.clockworkmod.com/ ，并配置环境变量\n\n**Mac**\n\n使用 brew 进行安装 `brew cask install android-platform-tools`\n\n\n\n安装完后插入安卓设备且安卓已打开 USB 调试模式，终端输入 `adb devices` ，显示设备号则表示成功。我手上的机子是坚果 pro1，第一次不成功,查看设备管理器有叹号，使用 [handshaker](https://www.smartisan.com/apps/handshaker) 加载驱动后成功，也可以使用豌豆荚之类的试试。\n\n```\nList of devices attached\n6934dc33    device\n```\n\n若不成功，可以参考[Android 和 iOS 操作步骤](https://github.com/wangshub/wechat_jump_game/wiki/Android-%E5%92%8C-iOS-%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4)进行修改\n\n#### 2. 安装 python 3\n#### 3. 安装所需 python 包\n\n命令行：\n`pip install -r requirements.txt`\n\n或者\n```\npip install pytesseract\npip install pillow  \npip install requests\npip install colorama\npip install baidu-aip\n```\n#### 4. 安装 谷歌 Tesseract\n\nWindows下链接：\n*推荐使用安装版，在安装时选择增加中文简体语言包*\n- 安装版：\n  https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-3.05.01.exe\n- 免安装版：\n  https://github.com/parrot-office/tesseract/releases/download/3.5.1/tesseract-Win64.zip\n  *免安装版需要下载[中文语言包](https://github.com/tesseract-ocr/tesseract/wiki/Data-Files)，放置到Tesseract的`tessdata`目录下*\n\n其他系统：\nhttps://github.com/tesseract-ocr/tesseract/wiki\n\n#### 5. 修改  `config/configure.conf` 中相应参数信息\n```\n[region]\n# 题目与选项区域\nquestion_region = 50, 350, 1000, 560\nchoices_region = 75, 535, 1000, 1200\n\n# 题目和选项一起的区域\ncombine_region = 50, 350, 1000, 1200\n\n[tesseract]\n# windows\n# tesseract 安装路径\ntesseract_cmd = C:\\\\Program Files (x86)\\\\Tesseract-OCR\\\\tesseract\n\n# 语言包目录和参数\ntessdata_dir_config = --tessdata-dir \"C:\\\\Program Files (x86)\\\\Tesseract-OCR\\\\tessdata\" --psm 6\n\n# mac 环境, 文件夹分割请使用 / 代替 \\\\ 如 '/usr/local/Cellar/tesseract/3.05.01/bin/tesseract'\n```\n\n**注： 可以用 `GetImgTool.py` 调整题目截取位置**\n可以到[这里](/config/devicesCutConfig.txt)查看部分手机截图设置\n\n#### 6. 运行脚本\n\n`python GetQuestionAndroid.py`\n会自动识别文字并打开浏览器\n\n### IOS\n\n**部分朋友成功**\n\n- 需要安装 WDA 进行截图，参考\n  -  [iOS 真机如何安装 WebDriverAgent](https://testerhome.com/topics/7220) \n  -  [Android 和 iOS 操作步骤](https://github.com/wangshub/wechat_jump_game/wiki/Android-%E5%92%8C-iOS-%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4)\n- 安装 [python-wda](https://github.com/openatx/facebook-wda)\n- 其他步骤相同。\n- `python GetQuestionIos.py`\n\n## 使用步骤 (百度 OCR)\n\n1. 在[百度平台](https://cloud.baidu.com/product/ocr)上创建应用申请 API Key 和 Secret Key\n\n2. 安装所需 python 包\n\n   命令行：\n\n   `pip install -r requirements.txt`\n\n   或者\n\n       pip install pytesseract\n       pip install pillow  \n       pip install requests\n       pip install colorama\n       pip install baidu-aip\n\n   ​\n\n3. 在 `config/configure.conf` 中加入相应 key, 并设置截取区域\n\n      ```\n      [region]\n      # 题目和选项一起的区域\n      combine_region = 50, 350, 1000, 1200\n      [baidu_api]\n      APP_ID = \n      API_KEY = \n      SECRET_KEY = \n      ```\n\n4. 在`GetQuestionAndroid.py`中切换识别方法\n\n  ```\n  #ocr_img: 需要分别截取题目和选项区域，使用 Tesseract\n  #ocr_img_tess： 题目和选项一起截，使用 Tesseract\n  #ocr_img_baidu： 题目和选项一起截，使用 baidu ocr，需配置 key\n      \n  # question, choices = ocr.ocr_img(img, config)\n  # question, choices = ocr.ocr_img_tess(img, config)\n  question, choices = ocr.ocr_img_baidu(img, config)\n  ```\n\n5. 其它环境配置与 Tesseract 步骤相同\n\n6. 运行脚本 \n\n   安卓： `python GetQuestionAndroid.py`\n\n\n\n## 其它\n- Tesseract 参数，若识别有问题可以更改参数解决\n  https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc\n\n- 结果分析三种方法可以选择，可以加`#`注释掉只保留一个方法\n\n- windows 命令行有很多乱码问题，建议使用 [cmder](http://cmder.net/) 作为命令工具，可以支持 linux 命令\n\n- 版本说明\n\n  - [简单验证思路访问浏览器版本](/simpleVersion)\n\n  - 最新版本：本目录\n\n    ​\n\n\n## 总结\n\n有了 ADB 截图，能玩出更多花样。python 写小脚本真的很方便。\n\n## Next\n\n- 文字识别后 nlp 处理一下关系，然后搜索不同选择结果\n\n\n\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSkyexu%2FTopSup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSkyexu%2FTopSup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSkyexu%2FTopSup/lists"}