目录

MLDocumentAnalyzer

Class Info

com.huawei.hms.mlsdk.document.MLDocumentAnalyzer

Detects document information (MLDocument) in images of documents by calling the cloud API.

You can create a document analyzer in either of the following ways:
  • Default mode: MLAnalyzerFactory.getInstance().getRemoteDocumentAnalyzer(). By default, the system automatically identifies languages without verifying the certificate fingerprint.
  • Customized mode: MLAnalyzerFactory.getInstance().getRemoteDocumentAnalyzer(MLDocumentSetting setting). You can set the languages to be detected and whether to enable certificate fingerprint verification.

Sample code:

// Create a document analyzer that uses the default configuration.
MLDocumentAnalyzer analyzer = MLAnalyzerFactory.getInstance().getRemoteDocumentAnalyzer();
// Create an MLFrame using the bitmap.
MLFrame frame = MLFrame.fromBitmap(bitmap);
// Create a document detection task.
Task<MLDocument> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<MLDocument>() {
    @Override
    public void onSuccess(MLDocument document) {
        // Recognition success.
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(Exception e) {
        // If the recognition fails, obtain related exception information.
        try {        
            MLException mlException = (MLException) e;
            // Obtain the result code. You can process the result code and customize respective messages displayed to users.
            int errorCode = mlException.getErrCode();
            // Obtain the error message. You can quickly locate the fault based on the result code.
            String errorMessage = mlException.getMessage();    
        } catch (Exception error) {
           // Handle the conversion error.
        }
    }
});

Public Method Summary

Qualifier and Type

Method Name and Description

com.huawei.hmf.tasks.Task<MLDocument>

asyncAnalyseFrame(MLFrame frame)

Detects document information in an input image.

void

close() throws IOException

Releases resources, including input and output streams.

void

stop() throws IOException

Releases resources, including input and output streams.

Public Methods

[h2]asyncAnalyseFrame(MLFrame frame)

Method

public com.huawei.hmf.tasks.Task<MLDocument> asyncAnalyseFrame(MLFrame frame)

Detects document information in an input image. For details about the error codes returned by the API, please refer to Error Codes.

Parameters

Name

Description

frame

Image to be detected.

Return

Type

Description

com.huawei.hmf.tasks.Task<MLDocument>

Asynchronous task that encapsulates the detection result.

[h2]close()

Method

public void close() throws IOException

Releases resources, including input and output streams.

Throws

Name

Description

IOException

If input or output streams are abnormal during resource release.

[h2]stop()

Method

public void stop() throws IOException

Releases resources, including input and output streams.

Throws

Name

Description

IOException

Exception that occurs in the input and output streams during resource release.