Skip to content

Instantly share code, notes, and snippets.

@hsiaoer
hsiaoer / includeRepo.xml
Created June 11, 2019 15:53
Include the repo to fritz-repository
allprojects {
repositories {
maven {
url "https://raw.github.com/fritzlabs/fritz-repository/master"
}
}
}
@hsiaoer
hsiaoer / HairSeg-RunPrediction.java
Created April 25, 2019 21:50
HairSeg - Run Prediction
// Run the image through the model to identify pixels representing hair.
FritzVisionSegmentResult segmentResult = predictor.predict(visionImage);
@hsiaoer
hsiaoer / HairSeg-CreateBlendedBitmap.java
Last active April 25, 2019 21:49
Hair Seg - Create Blended Bitmap
// Get the original image.
FritzVisionImage visionImage = segmentResult.getOriginalImage();
// Blend the original image with the mask and the blend mode.
Bitmap blendedBitmap = visionImage.blend(maskBitmap, blendMode);
@hsiaoer
hsiaoer / HairSeg-OverlayBitmap.java
Created April 25, 2019 21:35
Hair Seg - Overlay Bitmap
Bitmap maskBitmap = segmentResult.createMaskOverlayBitmap(blendMode.getAlpha());
@hsiaoer
hsiaoer / HairSeg-CreatePredictor.java
Last active September 11, 2019 14:31
Hair Seg - Create Predictor
// Initialize the model included with the app
SegmentOnDeviceModel onDeviceModel = new HairSegmentationOnDeviceModelFast();
// Create the predictor with the Hair Segmentation model.
FritzVisionSegmentPredictor predictor = FritzVision.ImageSegmentation.getPredictor(onDeviceModel);
@hsiaoer
hsiaoer / HairSeg-BlendModes.java
Last active September 11, 2019 14:32
Hair Seg - Blend Modes
// Soft Light Blend
BlendMode blendMode = BlendMode.SOFT_LIGHT;
// Color Blend
BlendMode blendMode = BlendMode.COLOR;
// Hue Blend
BlendMode blendMode = BlendMode.HUE;
@hsiaoer
hsiaoer / HairSeg-createImage.java
Last active September 11, 2019 14:35
Hair Seg - Create Image
// Determine how to rotate the image from the camera used.
ImageRotation rotation = FritzVisionOrientation.getImageRotationFromCamera(this, cameraId);
// Create a FritzVisionImage object from android.media.Image
FritzVisionImage visionImage = FritzVisionImage.fromMediaImage(image, rotation);
@hsiaoer
hsiaoer / createFVImage.java
Last active September 11, 2019 14:47
ImageSegmentationTutorial-createFVImage
// ---------------------------------
// Handle Bitmap (ARG_8888)
// ---------------------------------
// Standard FritzVisionImage creation
FritzVisionImage visionImage = FritzVisionImage.fromBitmap(bitmap);
// Applying a rotation to the bitmap (how to get the rotation value)
// https://stackoverflow.com/questions/7286714/android-get-orientation-of-a-camera-bitmap-and-rotate-back-90-degrees
FritzVisionImage visionImage = FritzVisionImage.fromBitmap(bitmap, rotation);
@hsiaoer
hsiaoer / setupPredictor.java
Last active September 11, 2019 14:47
ImageSegmentationTutorial-setupPredictor
@Override
protected void onCreate(final Bundle savedInstanceState) {
// ...
// PeopleSegmentOnDeviceModel is a subclass of FritzOnDeviceModel
PeopleSegmentOnDeviceModel onDeviceModel = new PeopleSegmentOnDeviceModelFast();
// Get the predictor with the People Segmentation Model
// FritzVisionSegmentPredictor is a subclass of FritzVisionPredictor
FritzVisionSegmentPredictor predictor = FritzVision.ImageSegmentation.getPredictor(onDeviceModel);
}
@hsiaoer
hsiaoer / completePrediction.java
Last active April 8, 2022 16:01
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);