hms-ml-demo
hms-ml-demo copied to clipboard
Hair Segmentation Not working
Hey team, I am trying to run hair segmentation but it is not working and is returning null image as output.
private void createImageTransactor(Bitmap bitmap) {
MLImageSegmentationSetting setting = new MLImageSegmentationSetting
.Factory()
// Set the segmentation mode to hair segmentation.
.setAnalyzerType(MLImageSegmentationSetting.HAIR_SEG)
.create();
MLImageSegmentationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting);
MLFrame frame = MLFrame.fromBitmap(bitmap);
Task<MLImageSegmentation> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(segmentation -> {
// Detection success.
foregroundBitmap = segmentation.foreground;
imageView.setImageBitmap(foregroundBitmap);
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// Detection failure.
}
});
}
Here is the dependencies graph.
// Import the base SDK. implementation 'com.huawei.hms:ml-computer-vision-segmentation:2.2.0.300' // Import the multiclass segmentation model package. implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-multiclass-model:2.2.0.300' // Import the human body segmentation model package. implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:2.2.0.300' // Import the hair segmentation model package. implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-hair-model:2.2.0.300'
You can refer to the answer on StackOverflow