Skip to content

MaskBinaryPlugin

Binarization plugin for segmentation mask

Applies a mask binarization agains provided threshold. Plugin depends on MaskUploadPlugin that must be attached to the renderer to upload mask buffer in texture. It may be combined with other mask post-processing plugins. Order in which operation on mask are applied corresponds to the order in which plugins are attached to the renderer.

  • MaskProcessPlugin

new MaskBinaryPlugin(thresh, size?): MaskBinaryPlugin

Constructor

number = 0.55

Foreground threshold

Size

Size of segmentation mask

MaskBinaryPlugin

MaskProcessPlugin.constructor

protected optional fragSrc: string

Code of fragment shader (copy shader by default)

MaskProcessPlugin.fragSrc


protected inputs: string[]

Shader texiwure inputs (names of sampler uniforms)

MaskProcessPlugin.inputs


loaded: boolean

Loaded state

MaskProcessPlugin.loaded


ordinal: number

Ordinal number

MaskProcessPlugin.ordinal


protected optional renderer: Renderer<SegmentationResult>

Renderer loaded the plugin

MaskProcessPlugin.renderer


protected optional shader: ShaderProgram

Processing shader

MaskProcessPlugin.shader


protected size: Size

Size of segmentation mask texture

MaskProcessPlugin.size


protected uniforms: object = {}

Shader uniforms as name-type map object

[key: string]: UniformType

MaskProcessPlugin.uniforms


protected optional vertSrc: string

Vertex shader source (copy shader by default)

MaskProcessPlugin.vertSrc

dispose(): void

Dispose video plugin

void

MaskProcessPlugin.dispose


load(renderer): Promise<void>

Initialize plugin

Initializes mask processing shader.

Renderer<SegmentationResult>

Renderer this plugin is attached to

Promise<void>

Promise resolving when initialization is finished

MaskProcessPlugin.load


process(result): void

Process the segmentation mask

Main method implementing shader processing on the mask. It’s called by update() and could be overridden to add custom logic. Internally process() updates input mask object passed from tracking result, thus replacing mask in-place. Default implementation applies processing shader and updates segmentatin texture with its output.

BodyMaskTexture

Segmentation mask

void

MaskProcessPlugin.process


setupCamera(ratio, angle): void

Set camera parameters

Could be overridden to adjust plugin’s pipeline.

number

Aspect ration of input video

number

Vertical field of view in radians

void

MaskProcessPlugin.setupCamera


setupVideo(size): void

Set video size

Could be overridden to adjust plugin’s pipeline.

Size

Resolution of input video

void

MaskProcessPlugin.setupVideo


unload(): void

Reset plugin

Releases all resources initialized in load().

void

MaskProcessPlugin.unload


update(result, stream): Promise<void>

Update segmentation masks

Updates segmentation mask applying processing shader. The mask is updated in place within tracking result object, therefore next plugins in the pipeline will access updated mask and mask processings can be chained.

SegmentationResult

Results of video processing

HTMLCanvasElement

Captured video frame

Promise<void>

MaskProcessPlugin.update