答题辅助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 爬虫的工具列表大全
Jan 31 Python
python实现SOM算法
Feb 23 Python
dataframe设置两个条件取值的实例
Apr 12 Python
使用python将请求的requests headers参数格式化方法
Jan 02 Python
10 行Python 代码实现 AI 目标检测技术【推荐】
Jun 14 Python
python使用装饰器作日志处理的方法
Jul 11 Python
Django app配置多个数据库代码实例
Dec 17 Python
python利用JMeter测试Tornado的多线程
Jan 12 Python
python 成功引入包但无法正常调用的解决
Mar 09 Python
pycharm实现在子类中添加一个父类没有的属性
Mar 12 Python
python小程序之4名牌手洗牌发牌问题解析
May 15 Python
python爬虫要用到的库总结
Jul 28 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
2006/11/25 PHP
解析PHP中DIRECTORY_SEPARATOR,PATH_SEPARATOR两个常量的作用
2013/06/21 PHP
php检测useragent版本示例
2014/03/24 PHP
redirect_uri参数错误的解决方法(必看)
2017/02/16 PHP
PHP中isset、empty的用法与区别示例详解
2020/11/05 PHP
本地对象Array的原型扩展实现代码
2010/12/04 Javascript
详解AngularJS中的表达式使用
2015/06/16 Javascript
原生JavaScript实现动态省市县三级联动下拉框菜单实例代码
2016/02/03 Javascript
基于JavaScript实现回到页面顶部动画代码
2016/05/24 Javascript
js创建数组的简单方法
2016/07/27 Javascript
关于jquery layui弹出层的使用方法
2018/04/21 jQuery
js控制随机数生成概率代码实例
2019/03/21 Javascript
通过seajs实现JavaScript的模块开发及按模块加载
2019/06/06 Javascript
关于微信小程序获取小程序码并接受buffer流保存为图片的方法
2019/06/07 Javascript
使用Webpack提升Vue.js应用程序的4种方法(翻译)
2019/10/09 Javascript
vue下的@change事件的实现
2019/10/25 Javascript
关于vue属性使用和不使用冒号的区别说明
2020/10/22 Javascript
[01:18:33]Secret vs VGJ.S Supermajor小组赛C组 BO3 第一场 6.3
2018/06/04 DOTA
python xml.etree.ElementTree遍历xml所有节点实例详解
2016/12/04 Python
深入理解Python分布式爬虫原理
2017/11/23 Python
深入分析python数据挖掘 Json结构分析
2018/04/21 Python
python实现Flappy Bird源码
2018/12/24 Python
python实现播放音频和录音功能示例代码
2018/12/30 Python
Python在cmd上打印彩色文字实现过程详解
2019/08/07 Python
python3 使用Opencv打开USB摄像头,配置1080P分辨率的操作
2019/12/11 Python
python 图像的离散傅立叶变换实例
2020/01/02 Python
Canvas globalCompositeOperation
2018/12/18 HTML / CSS
匈牙利墨盒和碳粉购买网站:CDRmarket
2018/04/14 全球购物
人力资源部经理助理岗位职责
2014/03/04 职场文书
《画家乡》教学反思
2014/04/22 职场文书
年度优秀员工获奖感言
2014/08/15 职场文书
国家税务局领导班子对照检查材料思想汇报
2014/10/04 职场文书
安全生产先进个人总结
2015/02/15 职场文书
浅谈PostgreSQL表分区的三种方式
2021/06/29 PostgreSQL
Python Matplotlib绘制条形图的全过程
2021/10/24 Python
uni-app 微信小程序授权登录的实现步骤
2022/02/18 Javascript