ML Kit: Document Recognition Development Procedure

1,047 posts
Thanks Meter: 1,125
By XDARoni, XDA Community Manager on 12th June 2020, 11:42 PM
Post Reply Email Thread
HUAWEI ML Kit allows your apps to easily leverage Huawei's long-term proven expertise in machine learning to support diverse artificial intelligence (AI) applications throughout a wide range of industries. Thanks to Huawei's technology accumulation, HUAWEI ML Kit provides diversified leading machine learning capabilities that are easy to use, helping you develop various AI apps.

The document recognition service can recognize text with paragraph formats in document images. Document recognition involves a large amount of computing. The SDK calls the cloud API to recognize documents only in asynchronous mode. With the SDK, you can quickly build various document recognition apps.

The document recognition service can extract text from document images to convert paper documents into electronic copies, greatly improving the information input efficiency and reducing labor costs. For example, when medical and legal files need to be stored electronically, you can use this service to generate well-structured documents based on the text information in the file images. In this way, you can quickly record and archive the files.

1. Create a document analyzer. You are advised to use the provided custom document recognition parameter MLDocumentSetting to specify to-be-recognized languages and other settings to create a document analyzer. In this way, you will get a higher document recognition accuracy.
// Method 1: Use customized parameter settings. 
MLDocumentSetting setting = new MLDocumentSetting.Factory() 
    // Specify the languages that can be recognized, which should comply with ISO 639-1. 
    .setLanguageList(new ArrayList<String>(){{this.add("zh"); this.add("en");}}) 
    // Set the format of the returned text border box. 
    // MLRemoteTextSetting.NGON: Return the coordinates of the four vertices of the quadrilateral. 
    // MLRemoteTextSetting.ARC: Return the vertices of a polygon border in an arc. The coordinates of up to 72 vertices can be returned. 
MLDocumentAnalyzer analyzer =  
// Method 2: Use the default parameter settings to automatically detect languages for text recognition. The format of the returned text box is MLRemoteTextSetting.NGON. 
MLDocumentAnalyzer analyzer =  
2. Create an MLFrame using JPG, JPEG, PNG, and BMP images are supported.
// Create an MLFrame object using the bitmap, which is the image data in bitmap format. 
MLFrame frame = MLFrame.fromBitmap(bitmap);
3. Pass the MLFrame object to the asyncAnalyseFrame method for document recognition.
Task<MLDocument> task = analyzer.asyncAnalyseFrame(frame); 
task.addOnSuccessListener(new OnSuccessListener<MLDocument>() { 
    public void onSuccess(MLDocument document) { 
        // Recognition success. 
}).addOnFailureListener(new OnFailureListener() { 
    public void onFailure(Exception e) { 
        // Recognition failure. 
4. After the recognition is complete, stop the analyzer to release recognition resources.
if (analyzer != null) {
    try {
    } catch (IOException e) {
         // Exception handling.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes