hms-ml-demo icon indicating copy to clipboard operation
hms-ml-demo copied to clipboard

Hair Segmentation Not working

Open abi98213 opened this issue 2 years ago • 1 comments

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'

abi98213 avatar Sep 13 '21 09:09 abi98213

You can refer to the answer on StackOverflow

Mike-mei avatar Sep 23 '21 06:09 Mike-mei