In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Python calls Baidu AI how to achieve ID card identification, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Install the baidu-aip module
Press win+R to open cmd and enter it
Pip3 install baidu-aip
If the following interface appears, the baidu-aip module has been installed successfully:
If you want to quickly understand how to identify the business license code, you can skip the second part and look at the third part first.
2. Obtain Baidu AI API key
In the process of using python to identify ID card, there are three lines of code using Baidu AI interface key, so first explain how to obtain the key. First of all, go to the following official Baidu AI website: https://ai.baidu.com/tech/ocr
There is Baidu account to enter the account password to log in, do not click to register, according to the instructions to enter the relevant information to register.
After logging in, find the list of products in character recognition, and there is a card text recognition content below. Click to learn more.
It can be found that the card card text recognition contains some of our common document recognition, such as ID card, bank card, business license, hukou book, passport and so on. This paper describes the identification of business licenses. Interested students can study the identification of other documents by themselves. The following product list can be found in the details of card character recognition:
Find the ID card identification and click to learn more to enter the following interface:
Click use now and the following service agreement will appear:
Click "I have agreed to Baidu AI Open platform Service Agreement" to enter the following interface:
After the slide, click on the card card OCR, you can find other functions of the ID card, click the activate button.
You can go to the following screen to activate the payment page:
Before confirming the activation, the real name verification should be carried out first, and the real name verification can be completed by following the instructions.
Then you can check the identification feature to be activated, as follows:
Then click to pay, because the first number of times a day is free, and take the post-payment model, so there is no need to pay in advance. If the activation is successful, the following interface will appear:
After activation is successful, click create App in the overview.
Fill in the application name (just want a name that fits your application scenario), select the text recognition package name, select the application attribution, fill in the application description, and click create now.
Finally, click the application details to find the interface key we need (the value corresponding to the red box).
Third, call Baidu interface to identify ID card.
After installing the baidu-aip module and obtaining the Baidu AI interface key, you can call the Baidu interface to identify the ID card. ID card recognition has 500 free calls a day. First of all, let's take a look at the ID card we want to identify today.
This ID card is a virtual ID card downloaded on Baidu. If there is any infringement, please contact me to delete it. The specific python code to identify the ID card is as follows:
Import reimport osimport timefrom aip import AipOcros.chdir (ringing F:\ official account\ 27. Document identification') # set the path to the certificate storage APP_ID = 'XXX'API_KEY =' XXXXXXXX'SECRET_KEY = 'XXXXXXXXXXXX'# Baidu account and key Replace it with your picture = open ('2 _ ID card _ v3.jpgkeeper, 'rb') img = picture.read () # read the picture idCardSide =' front' # ID card front # idCardSide = 'back' # ID card back options = {} options [' detect_direction'] = 'true' # check whether the image is facing By default, options ['detect_risk'] =' false' # is not detected whether the ID card risk type client = AipOcr (APP_ID, API_KEY, SECRET_KEY) text = client.idcard (img, idCardSide, options) # identify the information in the picture concat_text = [] if isinstance (text, dict): words = text ['words_result'] for k, v in words.items (): print (u' {k}: {v}' .format (kumbk) Tt ['words']) tt = u' {k}: {v} '.format (kumbk, vSecretv [' words']) concat_text.append (tt) # parses the dictionary into a form we are familiar with
Note: the content in os.chdir should be replaced with the address where you store the picture, and APP_ID, API_KEY and SECRET_KEY should be replaced with the Baidu key you got at the end of the second chapter.
The results are as follows:
Compared with the original picture, it can be found that the birth was intercepted directly from the ID card number, and the address information may not be identified by reflection, so the result is empty. Here is an episode. I have been using ID card images in png format for call identification, but have been reporting the following error:
ConnectionError: ('Connection aborted.', ConnectionResetError (10054,' remote host forced an existing connection to be closed.' , None, 10054, None))
After the later adjustment to the jpg picture, there is no such problem, so it is recommended that the format of the picture should be set to jpg when identifying the ID card. To further standardize the output to a standard format, it is normalized by the following code:
Import pandas as pddate_concat_text = pd.DataFrame (concat_text) date_concat_text.columns = ['text'] df = date_concat_text ["text"] .str.split (':', expand=True) date_concat_text ['label'] = df.iloc [:, 0] date_concat_text [' content'] = df.iloc [:, 1] date_concat_text.to_csv ("id_card_to_text.csv")
The results are as follows:
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.