答题辅助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多线程编程(一):threading模块综述
Apr 05 Python
Python的GUI框架PySide的安装配置教程
Feb 16 Python
Python最火、R极具潜力 2017机器学习调查报告
Dec 11 Python
python的Crypto模块实现AES加密实例代码
Jan 22 Python
Python实现读取机器硬件信息的方法示例
Jun 09 Python
Python3.5迭代器与生成器用法实例分析
Apr 30 Python
Python基于OpenCV实现人脸检测并保存
Jul 23 Python
pytorch神经网络之卷积层与全连接层参数的设置方法
Aug 18 Python
python实现的按要求生成手机号功能示例
Oct 08 Python
python3的UnicodeDecodeError解决方法
Dec 20 Python
django-xadmin根据当前登录用户动态设置表单字段默认值方式
Mar 13 Python
python 实现mysql自动增删分区的方法
Apr 01 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
基于php验证码函数的使用示例
2013/05/03 PHP
laravel 配置路由 api和web定义的路由的区别详解
2019/09/03 PHP
pjblog修改技巧汇总
2007/03/12 Javascript
Prototype中dom对象方法汇总
2008/09/17 Javascript
javascript 读取XML数据,在页面中展现、编辑、保存的实现
2009/10/27 Javascript
javascript权威指南 学习笔记之null和undefined
2011/09/25 Javascript
PHP开发者必须掌握的6个关键字
2014/04/14 Javascript
jQuery中DOM树操作之复制元素的方法
2015/01/23 Javascript
Javascript中的arguments与重载介绍
2015/03/15 Javascript
你有必要知道的25个JavaScript面试题
2015/12/29 Javascript
jQuery实现的给图片点赞+1动画效果(附在线演示及demo源码下载)
2015/12/31 Javascript
AngularJS实现路由实例
2017/02/12 Javascript
JavaScript禁止微信浏览器下拉回弹效果
2017/05/16 Javascript
详解用vue.js和laravel实现微信支付
2017/06/23 Javascript
vue 2.0项目中如何引入element-ui详解
2017/09/06 Javascript
如何让你的JS代码更好看易读
2017/12/01 Javascript
浅析java线程中断的办法
2018/07/29 Javascript
JavaScript实现留言板案例
2020/03/17 Javascript
Vue-CLI 3 scp2自动部署项目至服务器的方法
2020/07/24 Javascript
urllib2自定义opener详解
2014/02/07 Python
python实现带验证码网站的自动登陆实现代码
2015/01/12 Python
python生成式的send()方法(详解)
2017/05/08 Python
深入flask之异步非堵塞实现代码示例
2018/07/31 Python
Python嵌套式数据结构实例浅析
2019/03/05 Python
django的auth认证,authenticate和装饰器功能详解
2019/07/25 Python
利用 Flask 动态展示 Pyecharts 图表数据方法小结
2019/09/04 Python
Django表单提交后实现获取相同name的不同value值
2020/05/14 Python
css3隔行变换色实现示例
2014/02/19 HTML / CSS
CSS3实现多样的边框效果
2018/05/04 HTML / CSS
HTML5的标签的代码的简单介绍 HTML5标签的简介
2012/05/28 HTML / CSS
科颜氏美国官网:Kiehl’s美国
2017/01/31 全球购物
印度排名第一的蛋糕、鲜花和礼品送货:Winni
2019/08/02 全球购物
商务考察邀请函范文
2014/01/21 职场文书
社区工作者感言
2014/03/02 职场文书
食品工程专业求职信
2014/06/15 职场文书
css 中多种边框的实现小窍门
2021/04/07 HTML / CSS