Skip to content

Instantly share code, notes, and snippets.

@hsiaoer
Last active April 8, 2022 16:01
Show Gist options
  • Save hsiaoer/c497c08a97e4e7bdae838282f3eb852f to your computer and use it in GitHub Desktop.
Save hsiaoer/c497c08a97e4e7bdae838282f3eb852f to your computer and use it in GitHub Desktop.
ImageSegmentationTutorial-completePrediction
// Create the on device model for People Segmentation
// PeopleSegmentationOnDeviceModel is a subclass of FritzOnDeviceModel
PeopleSegmentOnDeviceModelFast onDeviceModel = new PeopleSegmentOnDeviceModelFast();
// Get the predictor with the People Segmentation Model
// FritzVisionSegmentPredictor is a subclass of FritzVisionPredictor
FritzVisionSegmentPredictor predictor = FritzVision.ImageSegmentation.getPredictor(onDeviceModel);
// Create a a visionImage
FritzVisionImage visionImage = FritzVisionImage.fromBitmap(inputBitmap);
// Run predict on an image
// FritzVisionSegmentResult is a subclass of FritzVisionResult
FritzVisionSegmentResult segmentResult = predictor.predict(visionImage);
// Get a masked bitmap of People detected in the image.
// Set the max alpha to 255 and .5f for clippingScoresAbove and .5f for zeroingScoresBelow
// For more details on this option, take a look at the documentation:
// https://docs.fritz.ai/develop/vision/image-segmentation/android.html#run-prediction-on-fritzvisionimage
Bitmap peopleMask = segmentResult.buildSingleClassMask(MaskType.PERSON, 255, .5f, .5f);
// Return a cut out option of the person
// Set option to trim any transparent pixels.
Bitmap peopleInPhoto = visionImage.mask(peopleMask, true);
@bharshavardhan536
Copy link

bharshavardhan536 commented Apr 8, 2022

PeopleSegmentOnDeviceModelFast is not importing in my android studio and MaskType.PERSON is also showing error how to import that package. This is the error I am getting. How to solve them.
error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment