Picture achieve recognition text recognition text with Baidu

Baidu to use the API, you must first register Baidu developer before you can use the services Baidu: Map API, text-to-speech API, API ..... text recognition, text recognition of official documents: Character Recognition - Help and Support -Baidu cloud

Once registered, you need to use the following three fields:

APP_ID = '10xxxx57'

API_KEY = 'vxxxxxxxxxxxxxxxxxsZyuwz9yKS2EghBs'

SECRET_KEY = 'm7pjnSNCKZxxxxxxxxxxxxxxxswGmIO35zsi'

Then, to Baidu -aip library in Python: pip install baidu-aip

Finally, directly on the code:

# -*- coding: UTF-8 -*-
from aip import AipOcr
# 定义常量
APP_ID = 'XXXXXXXXX'
API_KEY = 'XXXXXXXXXXXXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'

client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

""" 读取图片 的方法"""
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

#定义图片的绝对路径
image = get_file_content('D:/共享文件夹/图片/123.png')

""" 调用通用文字识别(高精度版) """
restu1 = client.basicAccurate(image);

lists = restu1['words_result']      #列表
for listss in lists:
    print(listss['words'])

From https://blog.51cto.com/13577495/2352313

Guess you like

Origin www.cnblogs.com/hankleo/p/11290032.html