答题辅助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实现哈希表
Feb 07 Python
python实现的简单猜数字游戏
Apr 04 Python
Python实现霍夫圆和椭圆变换代码详解
Jan 12 Python
Python中常用信号signal类型实例
Jan 25 Python
使用python3+xlrd解析Excel的实例
May 04 Python
python opencv判断图像是否为空的实例
Jan 26 Python
pyqt5让图片自适应QLabel大小上以及移除已显示的图片方法
Jun 21 Python
浅谈PyQt5 的帮助文档查找方法,可以查看每个类的方法
Jun 25 Python
PyCharm无法引用自身项目解决方式
Feb 12 Python
python openCV实现摄像头获取人脸图片
Aug 20 Python
浅析python字符串前加r、f、u、l 的区别
Jan 24 Python
python+opencv实现目标跟踪过程
Jun 21 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
基于mysql的bbs设计(二)
2006/10/09 PHP
php使用mkdir创建多级目录入门例子
2014/05/10 PHP
php编写的一个E-mail验证类
2015/03/25 PHP
CI框架(CodeIgniter)实现的导入、导出数据操作示例
2018/05/24 PHP
PHP实现二维数组按照指定的字段进行排序算法示例
2019/04/23 PHP
PHP实现页面静态化深入讲解
2021/03/04 PHP
屏蔽script注入小例子
2013/11/12 Javascript
jQuery实现表单提交时判断的方法
2014/12/13 Javascript
AngularJS之ionic 框架下实现 Localstorage本地存储
2017/04/22 Javascript
ionic环境配置及问题详解
2017/06/27 Javascript
JS实现身份证输入框的输入效果
2017/08/21 Javascript
微信小程序 拍照或从相册选取图片上传代码实例
2019/08/28 Javascript
JS实现可控制的进度条
2020/03/25 Javascript
python 提取文件的小程序
2009/07/29 Python
用实例说明python的*args和**kwargs用法
2013/11/01 Python
python中defaultdict的用法详解
2017/06/07 Python
python timestamp和datetime之间转换详解
2017/12/11 Python
python并发2之使用asyncio处理并发
2017/12/21 Python
PyTorch上搭建简单神经网络实现回归和分类的示例
2018/04/28 Python
Python 新建文件夹与复制文件夹内所有内容的方法
2018/10/27 Python
Django 路由控制的实现
2019/07/17 Python
Python数据分析模块pandas用法详解
2019/09/04 Python
Windows下Anaconda安装、换源与更新的方法
2020/04/17 Python
python opencv图像处理(素描、怀旧、光照、流年、滤镜 原理及实现)
2020/12/10 Python
Python数据模型与Python对象模型的相关总结
2021/01/26 Python
String s = new String(“xyz”);创建了几个String Object?
2015/08/05 面试题
电子商务应届生自我鉴定
2014/01/13 职场文书
防沙治沙典型材料
2014/05/07 职场文书
英语自我介绍演讲稿
2014/09/01 职场文书
2014迎国庆标语大全
2014/09/19 职场文书
2014年业务工作总结
2014/11/17 职场文书
安全员岗位职责
2015/02/10 职场文书
确保工程质量承诺书
2015/04/29 职场文书
创业计划书之酒厂
2019/10/14 职场文书
jQuery class属性操作addClass()与removeClass()、hasClass()、toggleClass()
2021/03/31 jQuery
《总之就是很可爱》新作短篇动画《总之就是很可爱~制服~》将于2022年夏天播出
2022/04/07 日漫