public final class ImageLabeler

  1. Object
  2. ImageLabeler

ImplementsAutoCloseable, VisionAnalyzer<ImageLabel[]>

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().

Constructors

public ImageLabeler()Creates an analyzer using the platform default backend and options.
public ImageLabeler(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<ImageLabel[]> 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

ImageLabeler

public ImageLabeler()
Creates an analyzer using the platform default backend and options.

ImageLabeler

public ImageLabeler(VisionOptions options)
Creates a reusable analyzer with explicit backend and result options.

Parameters

options VisionOptions
configuration captured by this analyzer; null uses 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<ImageLabel[]> process(VisionImage image)
Starts one analysis using the retained native backend.

Parameters

image VisionImage
immutable encoded or raw input

Returns

asynchronous typed result

close

public final synchronized void close()
Idempotently releases the retained native backend.