[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201258006396920241&fid=0101187876626530001

Foreword

The previous articles have introduced the function development of using HMS ML Kit SDK to implement Smile Capture Snapshot, ID photo DIY and photo translation,this time I will introduce to you the use of HMS Machine Learning Service (ML Kit) bank card recognition SDK, quickly bind credit cards.

Application scenarios of bank card recognition

Before introducing the development steps, let ’s talk about the specific application scenarios of bank card recognition,For banking apps, mobile payments app, e-commerce apps, or other apps with payment functions, during the use process, we often encounter the following common application scenarios:

· Card payment

Commonly used in payment apps, or apps with payment functions，used to bind credit cards, UnionPay debit cards, and provide online payment functions

· transfer money

Commonly used in bank or payment apps to transfer funds to users of our bank or other banks.

· Real-name authentication, identity verification

For example, social APP,Complete quick real-name authentication through the identity information associated with the bank card.

Whether it is card tying, money transfer or identity verification，will encounter a critical step，enter bank card information,such as bank card number, validity period, etc.；Since bank card numbers tend to be longer,manual entry is very error-prone，poor user experience；With the help of the HMS ML Kit bank card specific recognition capability，Can easily deal with the above scenarios, quickly and accurately enter bank card information, improve user experience.

How to use Huawei bank card identification service

Bank card recognition service can input bank card information through video streaming,obtain the important text information such as the card number and expiration date of the bank card in the image.

[IMG="https://miro.medium.com/max/700/0*mETatEU3B6XNbZsW.png"]https://miro.medium.com/max/700/0*mETatEU3B6XNbZsW.png[/IMG]

Bank card identification provides processing plug-ins. Developers can integrate a bank card recognition plug-in without the need to process camera video stream data, thereby achieving rapid integration of bank card recognition capabilities.

Key process of integrated bank card identification service

[IMG="https://miro.medium.com/max/700/0*dMPwz1EnJFZvAaMy.png"]https://miro.medium.com/max/700/0*dMPwz1EnJFZvAaMy.png[/IMG]

Since Huawei provides a bank card identification plug-in, developers can directly call the bank card plug-in, so the development steps are simpler, and only need to pull up the interface to obtain the result to complete the identification of the card number.

publishing ur app on Huawei AppGallery can refer to：https://forums.developer.huawei.com...d=0201253492001500241&fid=0101187876626530001

Development steps

1 Development preparation

1.1 Add Huawei maven address in project-level gradle

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

1.2 Add SDK dependencies to the application-level build.gradle

dependencies{
// Introduce the basic SDK，please use the newest version according to the development
implementation 'com.huawei.hms:ml-computer-vision-bcr:1.0.3.303'
// Introduce bank card identification plugin package ，please use the newest version according to the development
implementation 'com.huawei.hms:ml-computer-card-bcr-plugin:1.0.3.300'
// Introduce bank card recognition model package ,please use the newest version according to the development
implementation 'com.huawei.hms:ml-computer-card-bcr-model:1.0.3.300' }

1.3Automatically download the incremental incremental model in the AndroidManifest.xml file

To enable the application to automatically update the latest machine learning model to the user device after the user installs your application from the Huawei application market, add the following statement to the AndroidManifest.xml file of the application：

<manifest
...
<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value= "bcr"/>
<!--If multiple models are required,set the parameter as follows:
android:value="object,ocr,face,label,icr,bcr,imgseg"-->
... </manifest>

1.4 Apply for camera and storage permissions in the AndroidManifest.xml file

<!--Camera permissions--> <uses-permission android:name="android.permission.CAMERA" />
<!--Use storage permissions--><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

2 Key steps in code development

2.1 Create a recognition result callback function

Overload onSuccess, onCanceled, onFailure, onDenied four methods; onSuccess means recognition success, MLBcrCaptureResult is recognition return result, onCanceled means user cancel, onFailure means recognition failure, onDenied means camera is unavailable

private MLBcrCapture.Callback callback = new MLBcrCapture.Callback() {
@Override
public void onSuccess(MLBcrCaptureResult bankCardResult){
// Identify successful processing。
}
@Override
public void onCanceled(){
// User cancel processing
}
// Callback method where no text information can be recognized or a system exception occurs during the recognition process。
// retCode：error code。
// bitmap：Card picture of failed test
@Override
public void onFailure(int retCode, Bitmap bitmap){
// Identify exception handling。
}
@Override
public void onDenied(){
// The camera does not support such scene processing。
} };

2.2 Set the identification parameters, call the captureFrame interface of the recognizer for recognition, and the recognition result will be returned through the callback function in step 2.1

private void startCaptureActivity(MLBcrCapture.Callback callback) {
MLBcrCaptureConfig config = new MLBcrCaptureConfig.Factory()
// Set the identification interface horizontal and vertical screen, support three modes：
// MLBcrCaptureConfig.ORIENTATION_AUTO: Adaptive mode, the physical sensor determines the display direction。
// MLBcrCaptureConfig.ORIENTATION_LANDSCAPE: Landscape mode。
// MLBcrCaptureConfig.ORIENTATION_PORTRAIT: Portrait mode。
.setOrientation(MLBcrCaptureConfig.ORIENTATION_AUTO)
.create();
MLBcrCapture bankCapture = MLBcrCaptureFactory.getInstance().getBcrCapture(config);
bankCapture.captureFrame(this, callback); }

2.3 In the callback of the detection button, the method defined in step 2.2 is called to realize bank card recognition

@Override
public void onClick(View v) {
switch (v.getId()) {
// detect button
case R.id.detect:
startCaptureActivity(callback);
break;
default:
break;
} }

Demo effect

[IMG="https://miro.medium.com/max/360/0*NWM403SXtGTndN55.gif"]https://miro.medium.com/max/360/0*NWM403SXtGTndN55.gif[/IMG]

github source

The source code has been uploaded to github, you can also improve this function together on github。

github source address：https://github.com/HMS-Core/hms-ml-demo

Bank card identification demo code path：MLKit-Sample\module-text\src\main\java\com\mlkit\sample\activity\BankCardRecognitionActivity.java

For more detailed development guide, refer to the official website of Huawei Developer