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:
|
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.
}
}
}); 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. |
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. |
Name | Description |
|---|---|
frame | Image to be detected. |
Type | Description |
|---|---|
com.huawei.hmf.tasks.Task<MLDocument> | Asynchronous task that encapsulates the detection result. |