Class ImageLabeler
java.lang.Object
com.codename1.ai.vision.ImageLabeler
- All Implemented Interfaces:
VisionAnalyzer<ImageLabel[]>, AutoCloseable
Classifies what an image contains, as ranked labels with confidences.
ImageLabeler labeler = new ImageLabeler(new VisionOptions()
.minimumConfidence(0.6f)
.maximumResults(5));
labeler.process(VisionImage.fromFile(photoPath)).ready(labels -> {
StringBuilder summary = new StringBuilder();
for (ImageLabel label : labels) {
summary.append(label.getText())
.append(" (")
.append(Math.round(label.getConfidence() * 100))
.append("%)\n");
}
resultLabel.setText(summary.toString());
labeler.close();
}).except(error -> {
Log.e(error);
labeler.close();
});
The label text is the portable part. ImageLabel.getIndex() is a
model class index that differs between backends and is -1 on Apple
Vision, so branch on ImageLabel.getText().
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an analyzer using the platform default backend and options.ImageLabeler(VisionOptions options) Creates a reusable analyzer with explicit backend and result options. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Idempotently releases the retained native backend.final booleanTests the exact feature/backend pair configured for this analyzer.final AsyncResource<ImageLabel[]> process(VisionImage image) Starts one analysis using the retained native backend.
-
Constructor Details
-
ImageLabeler
public ImageLabeler()Creates an analyzer using the platform default backend and options.- See Also:
-
ImageLabeler
Creates a reusable analyzer with explicit backend and result options.- Parameters:
options- configuration captured by this analyzer;nulluses defaults
-
-
Method Details
-
isSupported
public final boolean isSupported()Description copied from interface:VisionAnalyzerTests the exact feature/backend pair configured for this analyzer.- Specified by:
isSupportedin interfaceVisionAnalyzer<T>- Returns:
- whether this analyzer's feature/backend is available and open
-
process
Starts one analysis using the retained native backend.- Specified by:
processin interfaceVisionAnalyzer<T>- Parameters:
image- immutable encoded or raw input- Returns:
- asynchronous typed result
-
close
public final void close()Idempotently releases the retained native backend.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceVisionAnalyzer<T>
-