答题辅助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定时检查启动某个exe程序适合检测exe是否挂了
Jan 21 Python
Python文件夹与文件的操作实现代码
Jul 13 Python
Python跳出循环语句continue与break的区别
Aug 25 Python
Python迭代器和生成器定义与用法示例
Feb 10 Python
Selenium控制浏览器常见操作示例
Aug 13 Python
python中的json总结
Oct 11 Python
Python人脸识别第三方库face_recognition接口说明文档
May 03 Python
对Django 中request.get和request.post的区别详解
Aug 12 Python
python同步windows和linux文件
Aug 29 Python
Django中使用MySQL5.5的教程
Dec 18 Python
Python ORM框架Peewee用法详解
Apr 29 Python
如何基于python把文字图片写入word文档
Jul 31 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 empty(),isset(),is_null()的实例测试详解
2013/06/06 PHP
php实现zip文件解压操作
2015/11/03 PHP
PHP文件上传操作实例详解
2016/09/27 PHP
php 广告点击统计代码(php+mysql)
2018/02/21 PHP
php中对象引用和复制实例分析
2019/08/14 PHP
PHP基于phpqrcode类生成二维码的方法示例详解
2020/08/07 PHP
IE 上下滚动展示模仿Marquee机制
2009/12/20 Javascript
jQuery动态添加 input type=file的实现代码
2012/06/14 Javascript
javascript数组随机排序实例分析
2015/07/22 Javascript
jquery实现先淡出再折叠收起的动画效果
2015/08/07 Javascript
基于JavaScript代码实现微信扫一扫下载APP
2015/12/30 Javascript
封装获取dom元素的简单实例
2016/07/08 Javascript
轻松实现js弹框显示选项
2016/09/13 Javascript
js获取当前周、上一周、下一周日期
2017/03/19 Javascript
javascript 日期相减-在线教程(附代码)
2017/08/17 Javascript
Node.js+jade+mongodb+mongoose实现爬虫分离入库与生成静态文件的方法
2017/09/20 Javascript
原生js调用json方法总结
2018/02/22 Javascript
微信小程序实现批量倒计时功能
2020/11/01 Javascript
Vue数字输入框组件示例代码详解
2020/01/15 Javascript
JavaScript中使用Spread运算符的八种方法总结
2020/06/18 Javascript
如何优雅地处理Django中的favicon.ico图标详解
2018/07/05 Python
Python 一句话生成字母表的方法
2019/01/02 Python
python3转换code128条形码的方法
2019/04/17 Python
使用Python正则表达式操作文本数据的方法
2019/05/14 Python
python 使用matplotlib 实现从文件中读取x,y坐标的可视化方法
2019/07/04 Python
Pandas+Matplotlib 箱式图异常值分析示例
2019/12/09 Python
Python Map 函数的使用
2020/08/28 Python
全面总结使用CSS实现水平垂直居中效果的方法
2016/03/10 HTML / CSS
CSMA/CD介质访问控制协议
2015/11/17 面试题
外贸学院会计专业应届生求职信
2013/11/14 职场文书
酒店个人求职信范文
2014/01/25 职场文书
出售房屋委托书范本
2014/09/24 职场文书
开平碉楼导游词
2015/02/06 职场文书
运动会口号霸气押韵
2015/12/24 职场文书
创业计划书之蛋糕店
2019/08/29 职场文书
基于Python实现流星雨效果的绘制
2022/03/18 Python