Skip to content

ImageBuffer

Image buffer

Helper class grabbing images into internal storage. Used by VideoSource to grab video streams and Engine to resize images for faster processing. Image can be accessed by canvas or read as pixels.

new ImageBuffer(name): ImageBuffer

Constructor

string = "canvas"

Optional name of canvas

ImageBuffer

canvas: HTMLCanvasElement

Canvas to capture frames


protected context: null | CanvasRenderingContext2D = null

Context to capture frames


protected inputSize: Size

Size of the input


size: Size

Size of the frames


protected optional transform: [[number, number, number], [number, number, number]]

Image transformation matrix

capture(video): boolean

Grab frame

Grabs frame from video element or canvas into internal canvas. Automatically rescales an image if resolutions are different.

Element to grab image from

ImageBitmap | HTMLCanvasElement | HTMLVideoElement

boolean

True if image is grabbed, False otherwise


data(): undefined | ImageData

Get image buffer

Returns data buffer of image currently grabbed into canvas.

undefined | ImageData

Image data buffer on success, undefined otherwise


dispose(): void

Dispose video context object

void


fill(): void

Fill canvas with color

void


setup(size, transpose, flip, clip?): void

Set input video size and optional transformations

Transformations are applied in order traspose->flip->clip, mening that if for example transpose and flip.x are set than already transposed image will be flipped horizontally. If transpose is true, ImageBuffer width and height reflect this - they will be swapped against input (original) size.

Size

Video size

boolean = false

Image transposition

FlipFlags = ...

Image flipping flags

ClipRect

Clipping rectangle in [0..1] space

void