答题辅助python代码实现
作者:懒企鹅 发布时间:2022-06-30 19:57:35
标签:python,答题
本文实例为大家分享了答题辅助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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
来源:https://www.cnblogs.com/lanqie/p/8290590.html
0
投稿
猜你喜欢
- Microsoft SQL Server 2005 Mobile Edition 3.0 (SQL Server Mobile) 支持两种与
- PHP html_entity_decode() 函数实例把 HTML 实体转换为字符:<?php $str = "&
- 引用PyMongo>>> import pymongo创建连接Connection>>> import
- 前言对自己写的冗长代码,想重构但又无思路?小编整理了介绍python代码重构优化的一些方法,助你一臂之力。编写干净的 Pythonic 代码
- 简介本文主要简述如何通过sklearn模块来进行预测和学习,最后再以图表这种更加直观的方式展现出来数据集学习数据预测数据数据处理数据分离因为
- 本文实例讲述了django框架实现一次性上传多个文件功能。分享给大家供大家参考,具体如下:在用django 写文件上传的时候,从reques
- 这篇文章主要介绍了Python tkinter三种布局实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
- 返回页面的类容,weburl为页面urlFunction GetBytes(weburl) '创建
- redis模块的使用1.安装模块pip3 install redis2.导入模块import redis3.连接方式严格连接模式:r=red
- froglt 的站点:http://www.go2here.net 欢迎转载,请注明出处,未经作者允许,禁止一切商业应用。这是即
- #第一种def delRepeat(liebiao): for x in liebiao: while li
- Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型。一、创建字典字典由键和对应值成对组成。字典也
- 1、生成 servie.yaml1.1、yaml转jsonservice模板yamlapiVersion: v1kind: Servicem
- 原则一:注意WHERE子句中的连接顺序: ORACLE采用自下而上的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他WHERE
- 一般的防止被框架方式或者被框架后自动转向,方法如下: if (top.location != self.loc
- 本文实例讲述了Python实现的NN神经网络算法。分享给大家供大家参考,具体如下:参考自Github开源代码:https://github.
- import osimport sysimport MySQLdbdef getStatus(conn):  
- Sql Server 中一个非常强大的日期格式化函数: 获得当前系统时间,GETDATE(): 2008年01月08日 星期二 14:59
- 问题描述在电脑中重新安装Anaconda3&PyCharm后,运行原来的程序画图时出现了下图界面。不能弹出如下图所示的“figure”窗口。
- b.php的代码 <?php //只能通过post方式访问 if ($_SERVER['REQUEST_METHOD'