HMS ML Demo provides an example of integrating Huawei ML Kit service into applications. This example demonstrates how to integrate services provided by ML Kit, such as face detection, text recognition, image segmentation, asr, and tts.
public class ImageSegmentation {
private MLImageSegmentationAnalyzer analyzer;
public void analyzer(Bitmap src, MLCallBack mlCallBack) {
MLImageSegmentationSetting setting = new MLImageSegmentationSetting.Factory()
.setExact(true)
.setAnalyzerType(MLImageSegmentationSetting.BODY_SEG)
.setScene(MLImageSegmentationScene.FOREGROUND_ONLY)
.create();
this.analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting);
MLFrame mlFrame = new MLFrame.Creator().setBitmap(src).create();
Task<MLImageSegmentation> task = this.analyzer.asyncAnalyseFrame(mlFrame);
task.addOnSuccessListener(imageSegmentationResult -> {
if (imageSegmentationResult != null) mlCallBack.onMLCompleted(imageSegmentationResult);
else mlCallBack.onMLFailed();
}).addOnFailureListener(e -> mlCallBack.onMLFailed());
}
}
2021-08-04 00:35:50.103 32383-32383/maa.abc.background_changer E/ActivityThread: Failed to find provider info for com.huawei.hms
2021-08-04 00:35:50.109 32383-32383/maa.abc.background_changer E/AbstractInitializer: huawei_module_mlkit_imgseg -> No need to switch because the context of the dynamic module is null or the context of full sdk
2021-08-04 00:35:50.109 32383-32383/maa.abc.background_changer E/AbstractInitializer: huawei_module_mlkit_imgseg -> The context of the dynamic module belongs to LOCAL
2021-08-04 00:35:50.156 32383-32383/maa.abc.background_changer E/HIAI_DDK_MSG: /AiDllParser.cpp Load(45)::"dlopen load lib failed,lib[/system/lib64/libhiai_foundation.huawei.so],errmsg [dlopen failed: can't read file "/data/app/~~tmU2wHTAY38LvsdjeofDpA==/maa.abc.background_changer-QDVrIWUG8BkHCusrq3t_HQ==/lib/arm64": Is a directory]"