resize

abstract fun resize(frame: Frame): GPUFrame

Resize the given frame using the options this Resizer was configured with.

For maximum performance, the resolved session's native pixel format should be yuv-420-8-bit-full on iOS, and private on Android: then, set the frame output's pixel format to me.nathanfallet.visioncamera.TargetVideoPixelFormat.NATIVE on Android, and to me.nathanfallet.visioncamera.TargetVideoPixelFormat.NATIVE on iOS if the native pixel format really is yuv-420-8-bit-full (or me.nathanfallet.visioncamera.TargetVideoPixelFormat.YUV otherwise). To configure your session with the target pixel format, use a pixel format constraint.

For ML models that expect CHW / NCHW tensors, configure the Resizer with PixelLayout.PLANAR.

The returned GPUFrame must be disposed (via GPUFrame.dispose, or a use { } block) to ensure the pipeline can run continuously: the Resizer has one output buffer, so calling resize again while the previous GPUFrame is alive throws.

The frame is only read during this call: it can be disposed as soon as this returns.

val resizer = createResizer(options)
frameOutput.setOnFrameCallback { frame ->
frame.use {
resizer.resize(it).use { resized ->
val pixels = resized.getPixelBuffer()
// run your ML model...
}
}
}

Return

A GPUFrame of the converted and resized pixel data.

Throws

If this Resizer has been disposed, the previous GPUFrame is still alive, the frame has no native buffer or an unsupported pixel format, or the GPU pipeline failed.