public final class SelfieSegmenter
- Object
- SelfieSegmenter
ImplementsAutoCloseable, VisionAnalyzer<SegmentationMask>
Separates a person from the background, for background replacement or blur.
SelfieSegmenter segmenter = new SelfieSegmenter();
EncodedImage photo = EncodedImage.create(jpegBytes);
segmenter.process(VisionImage.encoded(jpegBytes)).ready(mask -> {
// Everything below 60% foreground confidence becomes transparent, so
// whatever is painted behind this image shows through.
Image person = mask.cutOut(photo, 0.6f);
preview.setIcon(person);
segmenter.close();
}).except(error -> {
Log.e(error);
segmenter.close();
});
The mask has the model’s own resolution rather than the frame’s;
SegmentationMask.cutOut(com.codename1.ui.Image, float) and
SegmentationMask.toMaskImage(int) rescale it for you.
Constructors
public SelfieSegmenter() | Creates an analyzer using the platform default backend and options. |
public SelfieSegmenter(VisionOptions options) | Creates a reusable analyzer with explicit backend and result options. |
Methods
public final synchronized boolean isSupported() | Tests the exact feature/backend pair configured for this analyzer. |
public final synchronized AsyncResource<SegmentationMask> process(VisionImage image) | Starts one analysis using the retained native backend. |
public final synchronized void close() | Idempotently releases the retained native backend. |
Inherited methods
Constructor details
SelfieSegmenter
public SelfieSegmenter()Creates an analyzer using the platform default backend and options.
See also
SelfieSegmenter
public SelfieSegmenter(VisionOptions options)Creates a reusable analyzer with explicit backend and result options.
Parameters
optionsVisionOptions- configuration captured by this analyzer;
nulluses defaults
Method details
isSupported
public final synchronized boolean isSupported()Tests the exact feature/backend pair configured for this analyzer.
Returns
whether this analyzer’s feature/backend is available and open
process
public final synchronized AsyncResource<SegmentationMask> process(VisionImage image)Starts one analysis using the retained native backend.
Parameters
imageVisionImage- immutable encoded or raw input
Returns
asynchronous typed result
close
public final synchronized void close()Idempotently releases the retained native backend.