码迷,mamicode.com
首页 > Windows程序 > 详细

百度api识别图片文字

时间:2019-06-20 11:13:37      阅读:620      评论:0      收藏:0      [点我收藏+]

标签:tesseract   span   secret   百度api   ast   ras   arp   webdriver   rate   

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from PIL import Image,ImageGrab,ImageEnhance
import pytesseract
import time,os
from 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‘))

百度api识别图片文字

标签:tesseract   span   secret   百度api   ast   ras   arp   webdriver   rate   

原文地址:https://www.cnblogs.com/nickshen/p/11057247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!