ImageClassifier class

Performs classification on images.

Signature:

export declare class ImageClassifier extends VisionTaskRunner 

Extends: VisionTaskRunner

Methods

Method Modifiers Description
classify(image, imageProcessingOptions) Performs image classification on the provided single image and waits synchronously for the response. Only use this method when the ImageClassifier is created with running mode image.
classifyForVideo(videoFrame, timestamp, imageProcessingOptions) Performs image classification on the provided video frame and waits synchronously for the response. Only use this method when the ImageClassifier is created with running mode video.
createFromModelBuffer(wasmFileset, modelAssetBuffer) static Initializes the Wasm runtime and creates a new image classifier based on the provided model asset buffer.
createFromModelPath(wasmFileset, modelAssetPath) static Initializes the Wasm runtime and creates a new image classifier based on the path to the model asset.
createFromOptions(wasmFileset, imageClassifierOptions) static Initializes the Wasm runtime and creates a new image classifier from the provided options.
setOptions(options) Sets new options for the image classifier.Calling setOptions() with a subset of options only affects those options. You can reset an option back to its default value by explicitly setting it to undefined.

ImageClassifier.classify()

Performs image classification on the provided single image and waits synchronously for the response. Only use this method when the ImageClassifier is created with running mode image.

Signature:

classify(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): ImageClassifierResult;

Parameters

Parameter Type Description
image ImageSource An image to process.
imageProcessingOptions ImageProcessingOptions the ImageProcessingOptions specifying how to process the input image before running inference. The classification result of the image

Returns:

ImageClassifierResult

ImageClassifier.classifyForVideo()

Performs image classification on the provided video frame and waits synchronously for the response. Only use this method when the ImageClassifier is created with running mode video.

Signature:

classifyForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): ImageClassifierResult;

Parameters

Parameter Type Description
videoFrame ImageSource A video frame to process.
timestamp number The timestamp of the current frame, in ms.
imageProcessingOptions ImageProcessingOptions the ImageProcessingOptions specifying how to process the input image before running inference. The classification result of the image

Returns:

ImageClassifierResult

ImageClassifier.createFromModelBuffer()

Initializes the Wasm runtime and creates a new image classifier based on the provided model asset buffer.

Signature:

static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array): Promise<ImageClassifier>;

Parameters