This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Remove background of input image based on an alpha mask. | |
/// | |
/// - Parameters: | |
/// - image: Image to mask | |
/// - mask: Input mask. Reduces pixel opacity by mask alpha value. For instance | |
/// an alpha value of 255 will be completely opaque, 0 will be completely transparent | |
/// and a value of 125 will be partially transparent. | |
/// - Returns: Image mask with background removed. | |
func createMask(of image: UIImage, fromMask mask: UIImage, withBackground background: UIImage? = nil) -> UIImage? { | |
guard let imageCG = image.cgImage, let maskCG = mask.cgImage else { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------------------------- | |
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Soft Light Blend | |
BlendMode blendMode = BlendMode.SOFT_LIGHT; | |
// Color Blend | |
BlendMode blendMode = BlendMode.COLOR; | |
// Hue Blend | |
BlendMode blendMode = BlendMode.HUE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
allprojects { | |
repositories { | |
google() | |
jcenter() | |
mavenCentral() | |
maven { | |
url "https://fritz.mycloudrepo.io/public/repositories/android" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snapshotOverlay.setCallback(new OverlayView.DrawCallback() { | |
@Override | |
public void drawCallback(final Canvas canvas) { | |
// 1. Resize the background image | |
Bitmap scaledBackgroundBitmap = BitmapUtils.resize(backgroundBitmap, cameraSize.getWidth(), cameraSize.getHeight()); | |
// 2. Draw the background to the canvas | |
canvas.drawBitmap(scaledBackgroundBitmap, new Matrix(), new Paint()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snapshotOverlay.setCallback(new OverlayView.DrawCallback() { | |
@Override | |
public void drawCallback(final Canvas canvas) { | |
// If the prediction has not run | |
if(segmentResult == null) { | |
return; | |
} | |
// STEP 6: Show the people segmentation result when the background hasn't been chosen. |
NewerOlder