目录

class info
com.huawei.hms.mlsdk.card.icr.MLIcrAnalyzer

On-device ID card analyzer, which is used to recognize ID card information in a supplied image, and call the on-device API (the detection model runs on the device). You can create an on-device ID card analyzer in either of the following ways based on the site requirements: // Method 1: Use default parameter settings.

MLIcrAnalyzer analyzer = MLCardAnalyzerFactory.getInstance().getIcrAnalyzer();

// Method 2: Use customized parameter settings.

MLIcrAnalyzer analyzer = MLCardAnalyzerFactory.getInstance().getIcrAnalyzer(setting);

Sample Code

  1. // Method 1: Use default parameter settings. The front side is recognized by default.
  2.   MLIcrAnalyzer analyzer = MLCardAnalyzerFactory.getInstance().getIcrAnalyzer();
  3.   // Method 2: Use customized parameter settings.
  4.   // setSideType: Set whether the front or back side of an ID card is to be recognized.
  5.   // MLIcrAnalyzerSetting.FRONT: The value is FRONT, indicating the front side.
  6.   // MLIcrAnalyzerSetting.BACK: The value is BACK, indicating the back side.
  7.   MLIcrAnalyzerSetting settings = new MLIcrAnalyzerSetting.Factory()
  8.      .setSideType(MLIcrAnalyzerSetting.FRONT)
  9.      .create();
  10.   MLIcrAnalyzer analyzer = MLCardAnalyzerFactory.getInstance().getIcrAnalyzer(settings);
  11.   // Construct MLFrame by using the bitmap. It is recommended that the image size be greater than or equal to 512 x 512.
  12.   MLFrame mlFrame = new MLFrame.Creator().setBitmap(bitmap).create();
  13.   // Pass the MLFrame object to the asyncAnalyseFrame method for card recognition.Recognize information from an ID card.
  14.   Task<MLIdCard> task = analyzer.asyncAnalyseFrame(mlFrame);
  15.   task.addOnSuccessListener(new OnSuccessListener<MLIdCard>() {
  16.      public void onSuccess(MLIdCard idCard) {
  17.          // Processing logic for recognition success.
  18.   }})
  19.   .addOnFailureListener(new OnFailureListener() {
  20.      public void onFailure(Exception e) {
  21.          // Processing logic for failure.
  22.   }});

Public Method Summary

Return typeMethod name
com.huawei.hmf.tasks.Task<MLIdCard>asyncAnalyseFrame(MLFrame frame)
MLIcrAnalyzercreate(MLApplication app.MLIcrAnalyzerSetting setting)
voidstop()throws IOException

Public Methods

Method
public com.huawei.hmf.tasks.Task<MLIdCard> asyncAnalyseFrame(MLFrame frame)
Recognizes ID card information in a supplied image by asynchronous call.

Parameters

Parameter nameParameter desc
frameImage to be recognized, which can be a bitmap.


Return

Typedesc
com.huawei.hmf.tasks.Task<MLIdCard>Returns the asynchronous task that encapsulates the recognition result. For details about the usage, see the sample code.
Method
public static synchronized MLIcrAnalyzer create(MLApplication app, MLIcrAnalyzerSetting setting)
Creates an on-device ID card analyzer object.

Parameters

Parameter nameParameter desc
appMLApplication instance.
settingOn-device ID card analyzer configuration instance.


Return

Typedesc
MLIcrAnalyzerReturns an on-device ID card analyzer instance.
Method
public void stop() throws IOException
Stops recognition and releases resources, including input and output streams.

Throws

Exception nameException desc
IOExceptionI/O exception in input and output streams.