def run(): while True: # 截图 t = time.clock() screenshot.check_screenshot() img = Image.open("./screenshot.png") config_ = config.load_config() # question, choices = ocr.ocr_img_tess(img, config_) question, choices = ocr.get_question_and_choices(img, config_) question = filter_symbol(question) # 多线程 m1 = Thread(methods.run_algorithm(0, question)) m2 = Thread(methods.run_algorithm(1, question)) m1.start() m2.start() end_time3 = time.clock() print('用时: {0}'.format(end_time3 - t)) go = input('输入回车继续运行,输入 n 回车结束运行: ') if go == 'n': break print('------------------------')
def game_fun(image_cut): screenshot.check_screenshot() while True: start = time.time() screenshot.pull_screenshot() # 截图参数 image_cut() q_filePath = "question.png" # c_filePath = "choices.png" question, choices = question_words(q_filePath, options) # choices = choices_words(c_filePath, options) ans = guess_answer(question, choices) rush_ans(ans) end = time.time() print(Fore.YELLOW + '+++++++++++++++++++++++++++++++++++++++++' + Fore.RESET) print(Fore.GREEN + '+++' + '程序用时:' + str(end - start) + '秒' + '+++' + Fore.RESET) print(Fore.YELLOW + '+++++++++++++++++++++++++++++++++++++++++' + Fore.RESET) go = raw_input('输入回车继续运行,输入 n 回车结束运行:') if go == 'n': break
(62,804,184,926),(200,804,324,926),(340,804,458,926),(480,804,598,926),(614,804,736,926),(754,804,872,926),(892,804,1012,926), (62,950,184,1070),(200,950,324,1070),(340,950,458,1070),(480,950,598,1070),(614,950,736,1070),(754,950,872,1070),(892,950,1012,1070), (62,1100,184,1220),(200,1100,324,1220),(340,1100,458,1220),(480,1100,598,1220),(614,1100,736,1220),(754,1100,872,1220),(892,1100,1012,1220), (62,1240,184,1360),(200,1240,324,1360),(340,1240,458,1360),(480,1240,598,1360),(614,1240,736,1360),(754,1240,872,1360),(892,1240,1012,1360), (62,1390,184,1510),(200,1390,324,1510),(340,1390,458,1510),(480,1390,598,1510),(614,1390,736,1510),(754,1390,872,1510),(892,1390,1012,1510), (62,1540,184,1660),(200,1540,324,1660),(340,1540,458,1660),(480,1540,598,1660),(614,1540,736,1660),(754,1540,872,1660),(892,1540,1012,1660)) # 截图位置中心 点击 h_px = ((128,722),(262,722),(404,722),(540,722),(680,722),(820,722),(956,722), (128,866),(262,866),(404,866),(540,866),(680,866),(820,866),(956,866), (128,1010),(262,1010),(404,1010),(540,1010),(680,1010),(820,1010),(956,1010), (128,1160),(262,1160),(404,1160),(540,1160),(680,1160),(820,1160),(956,1160), (128,1310),(262,1310),(404,1310),(540,1310),(680,1310),(820,1310),(956,1310), (128,1450),(262,1450),(404,1450),(540,1450),(680,1450),(820,1450),(956,1450), (128,1600),(262,1600),(404,1600),(540,1600),(680,1600),(820,1600),(956,1600)) ''' c_s_time = time.time() # 截图并上传 screenshot.check_screenshot() screenshot.pull_screenshot() c_e_time = time.time() print '截图耗时{}s'.format(c_e_time - c_s_time) ''' im = Image.open(r"./screenshot.png") # 截图存储dict mem_pic ={} # 存储数字与位置对应信息dict key_list = {} h_s_time = time.time() # 截图并处理
# -*- coding: utf-8 -*- from aip import AipOcr import screenshot import webbrowser import re import urllib.parse # 百度OCR API APP_ID = '' API_KEY = '' SECRET_KEY = '' client = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 截图 screenshot.check_screenshot() def get_file(filePath): with open(filePath, 'rb') as fp: return fp.read() image = get_file("./screenshot.png") """ 调用通用文字识别(高精度版) """ result = client.basicAccurate(image) words = result['words_result'] for word in words: matchData = re.match(r'^(\d\.)(.*\?+)', word['words']) if matchData: print(matchData.group(2))
import urllib.request, sys, base64, json, os, time, baiduSearch, screenshot, re from PIL import Image import asyncio import threading from common import config import pytesseract import re # 配置appcode config = config.open_accordant_config() start = time.time() # 开始截图 screenshot.check_screenshot() screenshot.pull_screenshot() host = 'http://text.aliapi.hanvon.com' path = '/rt/ws/v1/ocr/text/recg' method = 'POST' appcode = config['appcode'] # 汉王识别appcode(填你自己的) querys = 'code=74e51a88-41ec-413e-b162-bd031fe0407e' bodys = {} url = host + path + '?' + querys screenshot = Image.open(r"./screenshot.png") img_size = screenshot.size w = screenshot.size[0] h = screenshot.size[1] print("xx:{}".format(img_size)) arrayAnswer = []