当前位置:网站首页>HMS core machine learning service

HMS core machine learning service

2022-07-04 23:03:00 Just_ Paranoid

Machine learning services (ML Kit) Provide machine learning kits , Develop various applications for developers using machine learning capabilities , Provide quality experience . Thanks to Huawei's long-term technology accumulation ,ML Kit Easy to use for developers 、 Diverse services 、 Technology leading machine learning capabilities , Help developers develop all kinds of products faster and better AI application .

  1. Text module : Text recognition 、 Document recognition 、 ID card identification 、 Bank card identification 、 Universal card identification 、 Text translation 、 Language detection 、 Real time speech recognition 、 speech synthesis 、 Offline speech synthesis 、 Audio file transcribing 、 Voice recognition 、 Text embedding 、 Real time voice transcribe
  2. Visual modules : Image segmentation 、 Object detection and tracking 、 Image classification 、 Landmark recognition 、 Image super-resolution 、 Text image super resolution 、 Scene recognition 、 Form identification 、 Document correction
  3. Body block : Face detection 、3D Face detection 、 Human bone test 、 In vivo detection 、 Hand key point recognition 、 Gesture recognition 、 Face to face comparison
  4. Demo of custom model Demo

guide :
https://developer.huawei.com/consumer/cn/doc/development/hiai-Guides/service-introduction-0000001050040017

Service dependency list
https://developer.huawei.com/consumer/cn/doc/development/hiai-Guides/overview-sdk-0000001051070278

Text recognition

//1. Create a text parser MLTextAnalyzer Used to identify words in pictures , You can MLLocalTextSetting Set the recognized language , Without setting language, only Latin characters can be recognized by default . 

// Mode one : Configure the end-to-end text analyzer with default parameters , Only Latin characters can be recognized .
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer();

// Mode two : Use custom parameters MLLocalTextSetting Configure the end-to-side text analyzer .
MLLocalTextSetting setting = new MLLocalTextSetting.Factory()
    .setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)
    //  Set the recognition language .
    .setLanguage("zh")
    .create();
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting);

//2. adopt android.graphics.Bitmap establish MLFrame, Supported image formats include :jpg/jpeg/png/bmp, It is recommended to input the image aspect ratio range :1:2 To 2:1.
//  adopt bitmap establish MLFrame,bitmap For input Bitmap Format picture data .
MLFrame frame = MLFrame.fromBitmap(bitmap);

//3. The generated MLFrame Object passed to asyncAnalyseFrame Methods for character recognition .
Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<MLText>() {
    
    @Override
    public void onSuccess(MLText text) {
    
        //  Identify successful processing .
    }
}).addOnFailureListener(new OnFailureListener() {
    
    @Override
    public void onFailure(Exception e) {
    
        //  Identification failure handling .
    }
});

// The asynchronous invocation method is used in the sample code , Local text recognition also supports analyseFrame Synchronous call mode , Identify results with “MLText.Block” Array 
Context context = getApplicationContext();
MLTextAnalyzer analyzer = new MLTextAnalyzer.Factory(context).setLocalOCRMode(MLLocalTextSetting.OCR_DETECT_MODE).setLanguage("zh").create();
SparseArray<MLText.Block> blocks = analyzer.analyseFrame(frame);

//4. Identification complete , Stop the analyzer , Release identification resources . 
try {
    
    if (analyzer != null) {
    
        analyzer.stop(); 
    }
} catch (IOException e) {
    
    //  exception handling .
}

Still image detection

//1. Create a picture classification analyzer . You can customize classes by image classification MLLocalClassificationAnalyzerSetting Create Analyzer . 
//  Mode one : End side identification uses user-defined parameter configuration .
MLLocalClassificationAnalyzerSetting setting = 
    new MLLocalClassificationAnalyzerSetting.Factory()
        .setMinAcceptablePossibility(0.8f)
        .create(); 
MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer(setting);
//  Mode two : End side identification uses the default parameter configuration .
MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer();

//2. adopt android.graphics.Bitmap establish MLFrame, Supported image formats include :jpg/jpeg/png/bmp, It is suggested that the size of the picture should not be less than 112*112 Pixels .
//  adopt bitmap establish MLFrame,bitmap For input Bitmap Format picture data .
MLFrame frame = MLFrame.fromBitmap(bitmap);

//3. call asyncAnalyseFrame Method for image classification ( Error code information can be found in : Machine learning service error code ).
Task<List<MLImageClassification>> task = analyzer.asyncAnalyseFrame(frame); 
task.addOnSuccessListener(new OnSuccessListener<List<MLImageClassification>>() {
    
    @Override
    public void onSuccess(List<MLImageClassification> classifications) {
    
        //  Recognition success .
        //  Traverse the returned list MLImageClassification, Get classification name and other information .
    }
}).addOnFailureListener(new OnFailureListener() {
    
    @Override
    public void onFailure(Exception e) {
    
        //  Recognition failed .
        // Recognition failure.
        try {
    
            MLException mlException = (MLException)e;
            //  Get error code , Developers can handle error codes , According to the error code for differentiated page prompt .
            int errorCode = mlException.getErrCode();
            //  Get error information , Developers can combine error codes , Fast location problem .
            String errorMessage = mlException.getMessage();
        } catch (Exception error) {
    
            //  Conversion error handling .
        }
    }
});

//4. Identification complete , Stop the analyzer , Release detection resources .
try {
    
    if (analyzer != null) {
    
       analyzer.stop();
    }
} catch (IOException e) {
    
    //  exception handling .
}

// The asynchronous call method is used in the above example code , Image classification also supports the use of synchronous calls analyseFrame Function to get the detection result :
SparseArray<MLImageClassification> classifications = analyzer.analyseFrame(frame);
原网站

版权声明
本文为[Just_ Paranoid]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041944148770.html