Github.com/zhouxu88/OC…

OCR (Optical Character Recognition) refers to the process in which electronic devices (such as scanners or digital cameras) examine characters printed on paper, determine their shapes by detecting dark and bright patterns, and then translate the shapes into computer characters using Character Recognition methods.

rendering


About OCR character recognition technology, its complex, having a lot of official document and the final effect is not ideal, but also good, baidu’s platform is based on the improved AI, so today will bring baidu AI platform character recognition technology, can identify id card, bank card, driving license, the license plate, and other documents.

1, we need to enter baidu cloud word recognition development platform, a series of registration, login.



cloud.baidu.com/product/ocr
2. Create an application

When creating the application, we can write the application name casually, but we should pay attention to: we must write the package name of our project when writing the text recognition package name, otherwise it will prompt you to get the Token error when identifying, then we will directly create our application.

3. View the management application list

This is the application we just created, and we need to remember its API Key and Secret Key, which we might use in our project.

4. Click the SDK download at the bottom left of the application list, and the technical documents and SDK we need will be downloaded from the download interface. There is also a technical documentation in the SDK

After downloading the SDK and decompressing it, the directory is as follows:

To illustrate the function of these files, refer to a diagram from the official documentation

  • Libs: Contains the core JAR package and the SO file, which can be copied directly into your project’s LIBS

  • Ocr-ui: it provides a default UI for scanning, which we can use or not,

  • OCRDemo: OCRDemo is an official demo that can run directly. However, you must configure the AK and SK to run the demo. Otherwise, the system displays a Token failure message.

Necessary note: After reading here, you can tread less pits



Note: We must obtain AccessToken successfully before using baidu AI platform SDK

Baidu AI Open Platform uses OAuth2.0 authorization to call open API, which must include accesss_token parameter in URL when calling API. AccessToken can be obtained as AK/SK or authorized file.

The OCR Android SDK provides the following three methods for obtaining AccessToken.

Solution 1. Obtain the Token by API Key/Secret Key

So when you call AccessToken, you need to fill in the API Key/Secret Key of the application you just created. Note that the package name must be the same as the package name of your project, otherwise it will fail.

OCR.getInstance().initAccessTokenWithAkSk(new OnResultListener<AccessToken>() { @Override public void OnResult (AccessToken result) {// Call success, return AccessToken object String token = result.getAccesstoken (); } @override public void onError(OCRError error) {// Call failed, Returns OCRError subclass SDKError object}}, getApplicationContext(), "your application AK"," your application SK");Copy the code

Although the SDK encrypts the sensitive data transmitted on the network, AK/SK may be stolen on mobile devices because AK/SK is written in the code in plain text. Developers with security concerns can use the second licensing scheme.

Scheme 2. Authorization File (secure mode) Obtain the Token

This authentication scheme uses an authorization file to obtain AccessToken, cached locally. This type of authentication is recommended for developers with security concerns. After your mobile APP is distributed, the APP may be decomcompiled, so directly put AK/SK in the APP source code, there is a risk of theft. The authentication method of authorization file can effectively protect THE SECURITY of AK/SK in mobile devices. Even if an attacker intercepts traffic and steals authorization files, it will be difficult to steal your quota.

At this point, some of you are thinking, what is a license file? How do I get it?

  • Find the application in the app list

  • Download the authorization file of the application

  • Add the authorization file to the project Assets folder. The file name must be AIp. License

  • Call the initAccessToken method to initialize the OCR singleton to get AccessToken:

OCR.getInstance().initAccessToken(new OnResultListener<AccessToken>() { @Override public void onResult(AccessToken Return AccessToken object String token = result.getAccesstoken (); } @override public void onError(OCRError error) {OCRError subclass SDKError}}, getApplicationContext());Copy the code

In this way, you do not need to fill in your AK and SK, this authorization file is more secure, recommended use.

3. Self-service AccessToken management (not recommended)



API authentication authentication mechanism


Ocr.getinstance ().initWithToken(getApplicationContext(), "access_token");Copy the code



Ai.baidu.com/docs#/OCR-A…

The address of my personal integrated Demo is also posted at the top of the article

Scan the following TWO-DIMENSIONAL code or the public number search Android old bird development experience, you can follow [public number], continue to launch excellent articles