答题辅助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接收多播数据的代码
Mar 01 Python
python实现带声音的摩斯码翻译实现方法
May 20 Python
Python按行读取文件的简单实现方法
Jun 22 Python
python基础之入门必看操作
Jul 26 Python
Python常见工厂函数用法示例
Mar 21 Python
详解python异步编程之asyncio(百万并发)
Jul 07 Python
浅谈flask源码之请求过程
Jul 26 Python
Python爬取成语接龙类网站
Oct 19 Python
python并发编程 Process对象的其他属性方法join方法详解
Aug 20 Python
pygame编写音乐播放器的实现代码示例
Nov 19 Python
Python如何使用函数做字典的值
Nov 30 Python
python matplotlib.pyplot.plot()参数用法
Apr 14 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
让这部DC动画新作刷新你的认知
2020/03/03 欧美动漫
使用PHP模拟HTTP认证
2006/10/09 PHP
php获取表单中多个同名input元素的值
2014/03/20 PHP
PHP管理依赖(dependency)关系工具 Composer的自动加载(autoload)
2014/08/18 PHP
PHP获取文件扩展名的4种方法
2015/11/24 PHP
CI框架源码解读之URI.php中_fetch_uri_string()函数用法分析
2016/05/18 PHP
屏蔽PHP默认设置中的Notice警告的方法
2016/05/20 PHP
thinkPHP中volist标签用法示例
2016/12/06 PHP
PHP基于Redis消息队列实现发布微博的方法
2017/05/03 PHP
safari下载文件自动加了html后缀问题
2018/11/09 PHP
PHP实现的文件浏览器功能简单示例
2019/09/12 PHP
js 静态动态成员 and 信息的封装和隐藏
2011/05/29 Javascript
jQuery 取值、赋值的基本方法整理
2014/03/31 Javascript
教你JS中的运算符乘方、开方及变量格式转换
2016/08/09 Javascript
简述jQuery Easyui一些用法
2017/08/01 jQuery
vue中render函数的使用详解
2018/10/12 Javascript
对layui初始化列表的CheckBox属性详解
2019/09/13 Javascript
基于html+css+js实现简易计算器代码实例
2020/02/28 Javascript
Python中字典创建、遍历、添加等实用操作技巧合集
2015/06/02 Python
Python基础教程之正则表达式基本语法以及re模块
2016/03/25 Python
初学python的操作难点总结(新手必看篇)
2017/08/03 Python
python中virtualenvwrapper安装与使用
2018/05/20 Python
windows下numpy下载与安装图文教程
2019/04/02 Python
Python使用POP3和SMTP协议收发邮件的示例代码
2019/04/16 Python
python GUI库图形界面开发之PyQt5美化窗体与控件(异形窗体)实例
2020/02/25 Python
python开发实例之python使用Websocket库开发简单聊天工具实例详解(python+Websocket+JS)
2020/03/18 Python
python实现定时发送邮件到指定邮箱
2020/12/23 Python
英国香水店:The Perfume Shop
2017/03/27 全球购物
波兰数码相机及配件网上商店: Cyfrowe.pl
2017/06/19 全球购物
秋季开学典礼主持词
2014/03/19 职场文书
打造高效课堂实施方案
2014/03/22 职场文书
村创先争优活动总结
2014/08/28 职场文书
社区活动总结范文
2015/05/07 职场文书
留学文书中的个人陈述,应该注意哪些问题?
2019/08/23 职场文书
python使用pywinauto驱动微信客户端实现公众号爬虫
2021/05/19 Python
Win7/8.1用户可以免费升级到Windows 11系统吗?
2021/11/21 数码科技