GithubHelp home page GithubHelp logo

wantongtang / topsup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from skyexu/topsup

0.0 2.0 0.0 3.92 MB

答题辅助决策:冲顶大会等答题类游戏

Home Page: https://www.jianshu.com/p/dc828c4b901d

Python 100.00%

topsup's Introduction

答题辅助

这两天冲顶大会直播答题 APP 突然火了起来,萌生了使用截图,文字识别,搜索来做个小辅助的想法。使用文字识别搜索,只能增加准确率,保证不了全对。

非常感谢关注,欢迎大家PR新的想法和优化。

灵感来自:

微信跳一跳辅助

程序员如何玩转《冲顶大会》?

更新日志

  • 2018.01.11
    • 修复搜索可能的乱码等一些问题,多线程加快执行
  • 2018.01.10
    • 增加循环,无需重复加载,优化逻辑和显示 来自 issue #7。增加部分手机截图设置
    • 增加了截图传输效率,修改了识别参数,对图像进行灰度转化,去干扰,增加了识别准确率。结果判断使用了三种方式,对不同问题可以参考不同结果。

版本说明

具体做法

  1. ADB 获取手机截屏
adb shell screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png .
  1. OCR 识别题目与选项文字

两个方法:

  • 谷歌 Tesseract ,安装软件即可,接下来主要使用这个方法
  • 百度 OCR需要注册百度 API,每天调用次数有限
  1. 搜索判断

结果判断方式

  1. 直接打开浏览器搜索问题
  2. 题目+每个选项都通过搜索引擎搜索,从网页代码中提取搜索结果计数
  3. 只用题目进行搜索,统计结果页面代码中包含选项的词频

以下为两个示例结果

参考了 I Hacked HQ Trivia But Here’s How They Can Stop Me

使用步骤 (谷歌 Tesseract)

Android

1. 安装 ADB

windows

下载地址:https://adb.clockworkmod.com/

Mac

使用 brew 进行安装 brew cask install android-platform-tools

安装完后插入安卓设备且安卓已打开 USB 调试模式,终端输入 adb devices ,显示设备号则表示成功。我手上的机子是坚果 pro1,第一次不成功,查看设备管理器有叹号,使用 handshaker 加载驱动后成功,也可以使用豌豆荚之类的试试。

List of devices attached
6934dc33    device

若不成功,可以参考Android 和 iOS 操作步骤进行修改

2. 安装 python 3

3. 安装所需 python 包

命令行:

pip install pytesseract
pip install pillow  
pip install requests

4. 安装 谷歌 Tesseract

Windows下链接: 推荐使用安装版,在安装时选择增加中文简体语言包

其他系统: https://github.com/tesseract-ocr/tesseract/wiki

5. 修改 common/ocr.py 代码相应目录信息

# win环境
# tesseract 路径
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'
# 语言包目录和参数
tessdata_dir_config = '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata" --psm 6'

# mac 环境 记得自己安装训练文件
# tesseract 路径
#pytesseract.pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.01/bin/tesseract'
# 语言包目录和参数
#tessdata_dir_config = '--tessdata-dir "/usr/local/Cellar/tesseract/3.05.01/share/tessdata/" --psm 6'

6. 运行脚本

python GetQuestionTessAndroid.py 会自动识别文字并打开浏览器

注: 可以用 GetImgTool.py 调整题目截取位置 可以到这里查看部分手机截图设置 若屏幕分辨率不同,请在 ocr.py 中自行修改代码即可

# 切割题目和选项位置,左上角坐标和右下角坐标,自行测试分辨率
question_im = image.crop((50, 350, 1000, 560)) # 坚果 pro1
choices_im = image.crop((75, 535, 990, 1150))
# question = img.crop((75, 315, 1167, 789)) # iPhone 7P

IOS

部分朋友成功

使用步骤 (百度 OCR)

请移步,链接

其它

总结

有了 ADB 截图,怕是各种小辅助都可以玩了。python 写小脚本真的很方便。

Next

  • 文字识别后 nlp 处理一下关系,然后搜索不同选择结果

topsup's People

Contributors

skyexu avatar assey2018 avatar hh23485 avatar alfredcc avatar

Watchers

James Cloos avatar Richard M Wan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.