HMS-Core / hms-ml-demo

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.
https://developer.huawei.com/consumer/en/hms/huawei-mlkit?ha_source=hms1
Apache License 2.0
362 stars 120 forks source link

Hair Segmentation Not working #81

Open abi98213 opened 3 years ago

abi98213 commented 3 years ago

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'

Mike-mei commented 3 years ago

You can refer to the answer on StackOverflow