答题辅助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中的对象与类型
Dec 11 Python
Python实现简单的语音识别系统
Dec 13 Python
urllib和BeautifulSoup爬取维基百科的词条简单实例
Jan 17 Python
python实现逆序输出一个数字的示例讲解
Jun 25 Python
Python元组知识点总结
Feb 18 Python
python获取Linux发行版名称
Aug 30 Python
浅谈python之自动化运维(Paramiko)
Jan 31 Python
详解python 降级到3.6终极解决方案
Feb 06 Python
matplotlib.pyplot.plot()参数使用详解
Jul 28 Python
python中的测试框架
Nov 13 Python
详解pycharm的python包opencv(cv2)无代码提示问题的解决
Jan 29 Python
总结三种用 Python 作为小程序后端的方式
May 02 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 存取 MySQL 数据库的一个例子
2006/10/09 PHP
Stop SQL Server
2007/06/21 Javascript
半角全角相互转换的js函数
2009/10/16 Javascript
JS自定义功能函数实现动态添加网址参数修改网址参数值
2013/08/02 Javascript
js控制当再次点击按钮时的间隔时间
2014/06/03 Javascript
使用npm发布Node.JS程序包教程
2015/03/02 Javascript
JS如何判断是否为ie浏览器的方法(包括IE10、IE11在内)
2015/12/13 Javascript
微信小程序 火车票查询实例讲解
2016/10/17 Javascript
微信小程序 选择器(时间,日期,地区)实例详解
2016/11/16 Javascript
vuejs通过filterBy、orderBy实现搜索筛选、降序排序数据
2020/10/26 Javascript
JS给按钮添加跳转功能类似a标签
2017/05/30 Javascript
微信小程序 POST请求的实例详解
2017/09/29 Javascript
js断点调试心得分享(必看篇)
2017/12/08 Javascript
node puppeteer(headless chrome)实现网站登录
2018/05/09 Javascript
详解VUE自定义组件中用.sync修饰符与v-model的区别
2018/06/26 Javascript
使用Promise封装小程序wx.request的实现方法
2019/11/13 Javascript
微信浏览器下拉黑边解决方案 wScroollFix
2020/01/21 Javascript
[49:20]2014 DOTA2国际邀请赛中国区预选赛5.21 CIS VS TongFu
2014/05/22 DOTA
[16:14]教你分分钟做大人:米拉娜(HEROS)
2014/11/24 DOTA
python用字典统计单词或汉字词个数示例
2014/04/22 Python
Tornado Web服务器多进程启动的2个方法
2014/08/04 Python
python编码最佳实践之总结
2016/02/14 Python
Python实现快速排序算法及去重的快速排序的简单示例
2016/06/26 Python
wxpython中Textctrl回车事件无效的解决方法
2016/07/21 Python
python获取命令行输入参数列表的实例代码
2018/06/23 Python
pytorch .detach() .detach_() 和 .data用于切断反向传播的实现
2019/12/27 Python
python脚本监控logstash进程并邮件告警实例
2020/04/28 Python
Python脚本实现监听服务器的思路代码详解
2020/05/28 Python
Python 中Operator模块的使用
2021/01/30 Python
Lee牛仔裤澳大利亚官网:美国著名牛仔裤品牌
2017/09/02 全球购物
品学兼优的大学生自我评价
2013/09/20 职场文书
高二物理教学反思
2014/02/08 职场文书
我的梦想演讲稿
2014/04/30 职场文书
本科毕业生自荐信
2014/06/02 职场文书
个人四风问题整改措施思想汇报
2014/10/04 职场文书
走进毛泽东观后感
2015/06/04 职场文书