This article mainly introduced Python based on Baidu Ai's text recognition example, now share to everyone, but also for everyone to make a reference. Come and see it together.
Use Baidu Ai's text recognition library, make the invocation example, where filepath is the path of the picture, you can pass in a picture with text, to identify.
Download BAIDU-AIP This library, you can directly use PIP Download: Pip install BAIDU-AIP, can also be downloaded in development tools such as Pycharm.
Then run the following code.
#-*-Coding:utf-8-*-from AIP import AIPOCR import JSON # define Constants app_id = ' 9851066 ' api_key = ' lugbatgyrgoerr9fzb V4sqyk ' Secret_key = ' fb2mnz1c2uhltximflc4laxpg7cvfyjv ' # Initialize Aipface object AIPOCR = AIPOCR (app_id, Api_key, SECRET_KEY) # read Picture FilePath = "Wechatimg1.jpeg" def get_file_content (FilePath): with open (FilePath, ' RB ') as FP: return Fp.read () # define parameter variable options = { ' detect_direction ': ' True ', ' language_type ': ' Chn_eng ', ' # # Call Generic text recognition interface result = Aipocr.basicgeneral (Get_file_content (FilePath), options) print (Json.dumps (result). Decode ("Unicode-escape" ))
Output Result:
{"log_id": 1424393327, "direction": 0, "Words_result_num": 2, "Words_result": [{"Words": "No money!"}, {"Words": "Skill"}]}
I have a few errors in this recognition, and the picture is not clear about, the following is my recognition of the picture.
General text recognition return data parameter details
field
| required |
type |
description |
| Direction |
no |
number |
image direction, when detect_direction=true exists. --1: Undefined, -0: Forward, -1: Counterclockwise 90 degrees, -2: Counterclockwise 180 degrees, -3: Counterclockwise 270 degrees |
| log_id |
is the |
number |
unique log ID for problem targeting |
| words_result_num |
Yes |
n Umber |
Identifies the number of results, representing the number of elements in the Words_result |
| words_result |
Yes |
array |
locating and recognizing result arrays |
| +words |
no |
string |
Identify result string |