from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom PIL import Image,ImageGrab,ImageEnhanceimport pytesseractimport time,osfrom pytesseract import *from numpy import *from scipy import *from aip import AipOcr #brower = webdriver.Chrome()url = "http://passport.hualala.com/"brower.maximize_window()brower.get(url)time.sleep(1)bbox = (1509, 485, 1612, 527) #先确定X,Y坐标,然后在X坐标上加图片的宽度,Y坐标上加图片的高度(1516, 485, 1603, 527)im =ImageGrab.grab(bbox)im.save(‘./image_file/a.png‘)## 打开图片识别验识码image = Image.open(‘./image_file/a.png‘)image = image.convert("L")sharpness = ImageEnhance.Contrast(image)sharp_img = sharpness.enhance(9.0)sharp_img.save(‘./image_file/a1.png‘) k = Image.open(‘./image_file/a1.png‘)text = pytesseract.image_to_string(k)print(text) app_id = ‘16575748‘api_key = ‘cgRELw4wo2lajhaVjTXR7a9Q‘secret_key = ‘8FTRcbn3iYp3fGyIMhAQrWmSyUGN9BdU‘client = AipOcr(app_id, api_key, secret_key)i = open(‘./image_file/a1.png‘, ‘rb‘)img = i.read() print("正在识别图片---------")# message = client.basicGeneral(img)message = client.basicAccurate(img)print(message)print(message[‘words_result‘][0][‘words‘])i.close()with open(‘test.txt‘, "a+")as f: for k in message.get(‘words_result‘): f.writelines(k.get(‘words‘))
原文地址:https://www.cnblogs.com/nickshen/p/11057247.html
时间: 2024-10-26 01:50:35