答题辅助python代码实现


Posted in Python onJanuary 16, 2018

本文实例为大家分享了答题辅助python具体代码,供大家参考,具体内容如下

from screenshot import pull_screenshot
import time, urllib.request
 
try:
 import Image
except ImportError:
 from PIL import Image, ImageDraw
 
import pytesseract
 
# 屏幕顶端到问题的距离/屏幕高度,随分辨率变化(默认1920*1080)
top_off_c = 0.15
# 问题高度
que_h = 300
# 答案高度
ans_h = 170
 
# 左右偏移量
l_r_off = 40
 
 
def check(question, ans):
 q_url = "http://www.baidu.com/s?word=" + urllib.parse.quote(question)
 resp = urllib.request.urlopen(q_url)
 
 print(resp.read().decode("utf-8"))
 
 
def draw():
 img = Image.open('autojump.png')
 w, h = img.size
 draw = ImageDraw.Draw(img)
 draw.line((40, h * 0.15, w - 40, h * 0.15), fill="red")
 draw.line((40, h * 0.15 + 300, w - 40, h * 0.15 + 300), fill="red")
 
 draw.line((40, h * 0.15 + 470, w * 0.7, h * 0.15 + 470), fill="red")
 draw.line((40, h * 0.15 + 640, w * 0.7, h * 0.15 + 640), fill="red")
 draw.line((40, h * 0.15 + 810, w * 0.7, h * 0.15 + 810), fill="red")
 
 img.show()
 
 
def main():
 while True:
  print(">>>>>>")
  pull_screenshot()
  img = Image.open('autojump.png')
  img = img.convert('L')
  w, h = img.size
  img_q = img.crop((l_r_off, h * top_off_c, w - l_r_off, h * top_off_c + que_h))
  img_a = img.crop((l_r_off, h * top_off_c + que_h, w * 0.7, h * top_off_c + que_h + ans_h))
  img_b = img.crop((l_r_off, h * top_off_c + que_h + ans_h, w * 0.7, h * top_off_c + que_h + ans_h * 2))
  img_c = img.crop((l_r_off, h * top_off_c + que_h + ans_h * 2, w * 0.7, h * top_off_c + que_h + ans_h * 3))
  question = pytesseract.image_to_string(img_q, lang='chi_sim')
  ans_a = pytesseract.image_to_string(img_a, lang='chi_sim')
  ans_b = pytesseract.image_to_string(img_b, lang='chi_sim')
  ans_c = pytesseract.image_to_string(img_c, lang='chi_sim')
  question = question.replace(" ", "").replace(".", "")
  ans = ["1", "1", "1"]
  ans[0] = ans_a.replace(" ", "").replace(".", "")
  ans[1] = ans_b.replace(" ", "").replace(".", "")
  ans[2] = ans_c.replace(" ", "").replace(".", "")
 
  print(question.replace(" ", "").replace(".", ""))
  print(ans)
 
  check(question, ans)
  # draw()
 
  time.sleep(1)
 
 
if __name__ == '__main__':
 main()

 文字识别

sudo pip3 install pytesseract
sudo apt-get install tesseract-ocr

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python实现树莓派WiFi断线自动重连的实例代码
Mar 16 Python
30秒轻松实现TensorFlow物体检测
Mar 14 Python
Python可变参数*args和**kwargs用法实例小结
Apr 27 Python
Windows 8.1 64bit下搭建 Scrapy 0.22 环境
Nov 18 Python
Python、 Pycharm、Django安装详细教程(图文)
Apr 12 Python
python离线安装外部依赖包的实现
Feb 13 Python
python_array[0][0]与array[0,0]的区别详解
Feb 18 Python
简单了解django处理跨域请求最佳解决方案
Mar 25 Python
python实现俄罗斯方块小游戏
Apr 24 Python
8种常用的Python工具
Aug 05 Python
python 中[0]*2与0*2的区别说明
May 10 Python
使用pd.merge表连接出现多余行的问题解决
Jun 16 Python
python实现百万答题自动百度搜索答案
Jan 16 #Python
Python数据结构之双向链表的定义与使用方法示例
Jan 16 #Python
python+pillow绘制矩阵盖尔圆简单实例
Jan 16 #Python
Python面向对象编程之继承与多态详解
Jan 16 #Python
Python基于socket实现简单的即时通讯功能示例
Jan 16 #Python
python中将字典形式的数据循环插入Excel
Jan 16 #Python
python+tkinter编写电脑桌面放大镜程序实例代码
Jan 16 #Python
You might like
咖啡知识大全
2021/03/03 新手入门
使用 eAccelerator加速PHP代码的方法
2007/09/30 PHP
PHP队列用法实例
2014/11/05 PHP
PHP自定义函数获取URL中一级域名的方法
2016/08/23 PHP
PHP 实现字符串翻转(包含中文汉字)的实现代码
2017/04/01 PHP
php和C#的yield迭代器实现方法对比分析
2019/07/17 PHP
js可突破windows弹退效果代码
2008/08/09 Javascript
jQuery学习笔记 更改jQuery对象
2012/09/19 Javascript
javascript 实现 秒杀,团购 倒计时展示的记录 分享
2013/07/12 Javascript
jquery验证手机号码、邮箱格式是否正确示例代码
2013/07/28 Javascript
JavaScript禁止页面操作的示例代码
2013/12/17 Javascript
js分页工具实例
2015/01/28 Javascript
jQuery实现仿Alipay支付宝首页全屏焦点图切换特效
2015/05/04 Javascript
jQuery手机拨号界面特效代码分享
2015/08/27 Javascript
AngularJS 实现按需异步加载实例代码
2015/10/18 Javascript
基于NodeJS+MongoDB+AngularJS+Bootstrap开发书店案例分析
2017/01/12 NodeJs
基于jQuery实现简单人工智能聊天室
2017/02/10 Javascript
微信小程序如何获取用户信息
2018/01/26 Javascript
Vue中v-for的数据分组实例
2018/03/07 Javascript
angular4强制刷新视图的方法
2018/10/09 Javascript
详解小程序不同页面之间通讯的解决方案
2018/11/23 Javascript
浅谈layer的Icon样式以及一些常用的layer窗口使用方法
2019/09/11 Javascript
关于layui的下拉搜索框异步加载数据的解决方法
2019/09/28 Javascript
Python常见加密模块用法分析【MD5,sha,crypt模块】
2017/05/24 Python
Django压缩静态文件的实现方法详析
2018/08/26 Python
浅谈Python爬虫基本套路
2019/03/25 Python
Python完成毫秒级抢淘宝大单功能
2019/06/06 Python
Python及Pycharm安装方法图文教程
2019/08/05 Python
CSS3实现任意图片lowpoly动画效果实例
2017/05/11 HTML / CSS
W3C公布最新的HTML5标准草案
2008/10/17 HTML / CSS
工地安全检查制度
2014/02/04 职场文书
《故都的秋》教学反思
2014/04/15 职场文书
一个都不能少观后感
2015/06/04 职场文书
七年级作文之下雨天
2019/12/23 职场文书
tensorflow中的数据类型dtype用法说明
2021/05/26 Python
python中urllib包的网络请求教程
2022/04/19 Python