| 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); |
- // Method 1: Use default parameter settings. The front side is recognized by default.
- MLIcrAnalyzer analyzer = MLCardAnalyzerFactory.getInstance().getIcrAnalyzer();
- // Method 2: Use customized parameter settings.
- // setSideType: Set whether the front or back side of an ID card is to be recognized.
- // MLIcrAnalyzerSetting.FRONT: The value is FRONT, indicating the front side.
- // MLIcrAnalyzerSetting.BACK: The value is BACK, indicating the back side.
- MLIcrAnalyzerSetting settings = new MLIcrAnalyzerSetting.Factory()
- .setSideType(MLIcrAnalyzerSetting.FRONT)
- .create();
- MLIcrAnalyzer analyzer = MLCardAnalyzerFactory.getInstance().getIcrAnalyzer(settings);
- // Construct MLFrame by using the bitmap. It is recommended that the image size be greater than or equal to 512 x 512.
- MLFrame mlFrame = new MLFrame.Creator().setBitmap(bitmap).create();
- // Pass the MLFrame object to the asyncAnalyseFrame method for card recognition.Recognize information from an ID card.
- Task<MLIdCard> task = analyzer.asyncAnalyseFrame(mlFrame);
- task.addOnSuccessListener(new OnSuccessListener<MLIdCard>() {
- public void onSuccess(MLIdCard idCard) {
- // Processing logic for recognition success.
- }})
- .addOnFailureListener(new OnFailureListener() {
- public void onFailure(Exception e) {
- // Processing logic for failure.
- }});
| Return type | Method name |
| com.huawei.hmf.tasks.Task<MLIdCard> | asyncAnalyseFrame(MLFrame frame) |
| MLIcrAnalyzer | create(MLApplication app.MLIcrAnalyzerSetting setting) |
| void | stop()throws IOException |
| Method |
| public com.huawei.hmf.tasks.Task<MLIdCard> asyncAnalyseFrame(MLFrame frame) |
| Recognizes ID card information in a supplied image by asynchronous call. |
Parameters
| Parameter name | Parameter desc |
| frame | Image to be recognized, which can be a bitmap. |
Return
| Type | desc |
| 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 name | Parameter desc |
| app | MLApplication instance. |
| setting | On-device ID card analyzer configuration instance. |
Return
| Type | desc |
| MLIcrAnalyzer | Returns 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 name | Exception desc |
| IOException | I/O exception in input and output streams. |