Business card recognition, the simplest integrated strategy in history is here! With SDK package

Preface

Nowadays, interpersonal communication has become an indispensable part of life. It is a necessary step to transfer business cards to each other and record contact information. The business card bears all kinds of information about each other, such as name, company, address, etc. Generally speaking, We will compare the various information entered on the business card and tap the phone keyboard one by one. If you have business card recognition, you can reverse this phenomenon, easily complete business card recognition and enter business card information.

Introduction to business card recognition technology

Business card recognition uses OCR technology to convert and recognize the text on the business card into corresponding text that can be edited, and can classify and manage the recognized business card information. It supports the collection of business card information through photo recognition, QR code recognition, and import recognition. Users only need to place the business card in the preview box shot by the mobile phone to automatically complete a series of operations for business card recognition, which is very convenient.

Insert picture description here

Preparation steps before development

Before starting the API development work, you need to complete the necessary development preparations. At the same time, please ensure that the Maven warehouse address of the HMS Core SDK has been configured in your project, and the SDK integration of this service has been completed.

android studio installation

Very simple, just download and install. Specific download link:

Android studio official website download link: https://developer.android.com/studio
Android studio installation process reference link: https://www.cnblogs.com/xiadewang/p/7820377.html

Add Huawei maven warehouse in project-level gradle

Open the AndroidStudio project-level build.gradle file

Insert picture description here

maven address

Configure the maven warehouse address of the HMS SDK in buildscript->repositories

buildscript {
    
    
    repositories {
    
    
        maven {
    
     url 'https://developer.huawei.com/repo/' }
        
    }
}

Configure the maven warehouse address of the HMS SDK in allprojects -> repositories

allprojects {
    
    
    repositories {
    
    
        maven {
    
     url 'https://developer.huawei.com/repo/' }
        
    }
}

Introduce SDK
dependencies {
    
    
    // Text recognition SDK.
    implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.1.300'
    // Text recognition model.
    implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:2.0.1.300'
    implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:2.0.1.300'
    implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:2.0.1.300'
}

}
Manifest file
<manifest
    ...
    <meta-data
        android:name="com.huawei.hms.ml.DEPENDENCY"
        android:value="ocr" />
    ...
</manifest>
Authority
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.autofocus" />
Dynamic permission application
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    
    
    requestPermissions(new String[]{
    
    Manifest.permission.CAMERA}, CAMERA_REQUEST);

Development key steps

1. Create a text analyzer MLTextAnalyzer to recognize the text in the picture, use the custom parameter MLLocalTextSetting to configure the end-side text analyzer.
MLLocalTextSetting setting = new MLLocalTextSetting.Factory()
        .setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)
        .setLanguage("zh")
        .create();
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance()
        .getLocalTextAnalyzer(setting);

2. Create MLFrame through android.graphics.Bitmap. The supported image formats include: jpg/jpeg/png/bmp. It is recommended to enter the image aspect ratio range: 1:2 to 2:1.
MLFrame frame = MLFrame.fromBitmap(bitmap);
3. Pass the generated MLFrame object to the "asyncAnalyseFrame" method for text recognition.
Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<MLText>() {
    
    
    @Override
    public void onSuccess(MLText text) {
    
    
        // Recognition success.
        
    }
}).addOnFailureListener(new OnFailureListener() {
    
    
    @Override
    public void onFailure(Exception e) {
    
    
        // Recognition failure.
        
    }
});
4. After the recognition is complete, stop the analyzer and release the recognition resources.
try {
    
    
    if (analyzer != null) {
    
    
        analyzer.stop();
    }
} catch (IOException e) {
    
    
    // IOException
} catch (Exception e) {
    
    
    // Exception
}

Demo effect

In order to facilitate developers to better understand this scenario, we have also made a demo app to show the effect of business card recognition.
Insert picture description here
If you are interested in the implementation, you can download the source code on Github: https://developer.huawei.com/ consumer/cn/doc/HMSCore-Guides-V5/text-recognition-0000001050040053-V5#ZH-CN_TOPIC_0000001050750207__section16220018134717

Guess you like

Origin blog.csdn.net/weixin_47546655/article/details/108767741