Frame

A single Camera Frame, backed by a native buffer (an ImageProxy on Android, a CMSampleBuffer on iOS).

Lifetime contract: a Frame is only valid while isValid is true. The Camera pipeline has a small pool of buffers, so every Frame must be disposed as soon as possible, otherwise the pipeline stalls and frames get dropped (FrameDroppedReason.OUT_OF_BUFFERS). Accessing a disposed Frame throws. A Frame must not be shared across coroutines or stored beyond the processing callback.

Frame is AutoCloseable, so it can be used with use { }:

frame.use {
// processing...
}

Properties

Link copied to clipboard
abstract val bytesPerRow: Int

The number of bytes per row of this Frame's first plane.

Link copied to clipboard

The camera intrinsic matrix of this Frame (3x3, column-major, see CameraCalibrationData.cameraIntrinsicMatrix), or null if FrameOutputOptions.enableCameraMatrixDelivery is disabled. iOS only.

Link copied to clipboard
abstract val hasNativeBuffer: Boolean

Whether this Frame can be accessed as a NativeBuffer.

Link copied to clipboard
abstract val hasPixelBuffer: Boolean

Whether this Frame can be accessed on the CPU.

Link copied to clipboard
abstract val height: Int

The height of this Frame, in pixels.

Link copied to clipboard
abstract val isMirrored: Boolean

Whether this Frame is mirrored.

Link copied to clipboard
abstract val isPlanar: Boolean

Whether this Frame is planar (e.g. YUV), or interleaved (e.g. RGB).

Link copied to clipboard
abstract val isValid: Boolean

Whether this Frame is still valid, i.e. it has not been disposed yet.

Link copied to clipboard

The orientation of this Frame's content, relative to the output orientation.

Link copied to clipboard
abstract val pixelFormat: PixelFormat

The PixelFormat of this Frame.

Link copied to clipboard
abstract val timestamp: Long

The presentation timestamp of this Frame, in nanoseconds.

Link copied to clipboard
abstract val width: Int

The width of this Frame, in pixels.

Functions

Link copied to clipboard
open override fun close()

Same as dispose, to use a Frame with use { }.

Link copied to clipboard
abstract fun convertCameraPointToFramePoint(cameraPoint: Point): Point

Converts a point in the Camera's normalized coordinate system to this Frame's coordinate system.

Link copied to clipboard
abstract fun convertFramePointToCameraPoint(framePoint: Point): Point

Converts a point in this Frame's coordinate system to the Camera's normalized coordinate system.

Link copied to clipboard
abstract fun dispose()

Disposes this Frame, giving its buffer back to the Camera pipeline. Calling it more than once is a no-op.

Link copied to clipboard

Gets a NativeBuffer to this Frame's native platform buffer, for zero-copy GPU or ML processing. The returned buffer must be NativeBuffer.released before this Frame is disposed.

Link copied to clipboard
abstract fun getPixelBuffer(): ByteArray

Gets this Frame's pixel data, for non-planar Frames (e.g. RGB). For planar Frames, use getPlanes instead, as the content of this buffer is then platform specific.

Link copied to clipboard
abstract fun getPlanes(): List<FramePlane>

Gets the FramePlanes of this Frame, if it is planar (isPlanar), e.g. one full resolution Y plane and one half resolution UV plane in YUV. Returns an empty list for non-planar Frames.