Skip to content

Instantly share code, notes, and snippets.

@hsiaoer
Last active July 26, 2019 14:21
Show Gist options
  • Save hsiaoer/a28eedeb33cdb8ce3c1518de2b2e2df5 to your computer and use it in GitHub Desktop.
Save hsiaoer/a28eedeb33cdb8ce3c1518de2b2e2df5 to your computer and use it in GitHub Desktop.
ImageSegmentationTutorial-showPredictionResult
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.
if (backgroundBitmap == null) {
// Create the person mask
Bitmap personMask = segmentResult.buildSingleClassMask(MaskType.PERSON, 180, clippingThreshold, zeroCutoff);
// Overlay the mask on the original image
Bitmap result = visionImage.overlay(personMask);
// Scale the bitmap to the viewport
Bitmap scaledBitmap = BitmapUtils.resize(result, cameraSize.getWidth(), cameraSize.getHeight());
// Draw it on the canvas to render
canvas.drawBitmap(scaledBitmap, new Matrix(), new Paint());
return;
}
// ...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment