Python's example of word recognition based on Baidu AI

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.