Skip to content

PatchPlugin

Patch plugin

Plugin patches (inpaints/erases) foreground region of image defined by body segmentation mask from @geenee/bodyprocessors!PoseProcessor. It may be used in avatar virtual try to remove parts of a user’s body that stick out (not covered). Plugin depends on MaskUploadPlugin that must be attached to the renderer to upload mask in an image texture. One may utilize MaskUpscalePlugin that provides higher resolution segmentation that significantly increases accuracy of patching and reduces size of patch region. Other mask post-processing plugins may be attached.

new PatchPlugin(thresh, radius, maskSize): PatchPlugin

Constructor

number = 0.55

Foreground threshold

number = 512

Radius of foreground search

Size = ...

Size of segmentation mask

PatchPlugin

ShaderPlugin.constructor

protected optional fragSrc: string

Code of fragment shader (copy shader by default)

ShaderPlugin.fragSrc


protected optional inputs: string[]

Shader texture inputs (names of sampler uniforms)

ShaderPlugin.inputs


loaded: boolean

Loaded state

ShaderPlugin.loaded


protected maskSize: Size

Size of segmentation mask


ordinal: number

Ordinal number

ShaderPlugin.ordinal


protected radius: number = 512

Radius of foreground search


protected optional renderer: Renderer<SegmentationResult>

Renderer loaded the plugin

ShaderPlugin.renderer


protected optional shader: ShaderProgram

Rendering shader

ShaderPlugin.shader


protected optional shaderCtx: WebGL2RenderingContext

Rendering context

ShaderPlugin.shaderCtx


protected size: Size

Image size

ShaderPlugin.size


protected thresh: number = 0.55

Foreground threshold


protected optional uniforms: object

Shader uniforms as name-type map object

[key: string]: UniformType

ShaderPlugin.uniforms


protected optional vertSrc: string

Vertex shader source (copy shader by default)

ShaderPlugin.vertSrc

dispose(): void

Dispose video plugin

void

ShaderPlugin.dispose


load(renderer): Promise<void>

Initialize plugin

Initializes resources required for shader effect.

Renderer<SegmentationResult>

Renderer this plugin is attached to

Promise<void>

Promise resolving when initialization is finished

ShaderPlugin.load


process(result, input): Promise<boolean>

Process the image

Patches (inpaints) foreground image pixels according to provided segmentation mask.

SegmentationResult

Results of video processing

WebGLTexture

Current image texture

Promise<boolean>

True on success, false otherwise

ShaderPlugin.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

ShaderPlugin.setupCamera


setupVideo(size): void

Set video size

Adjusts shader and texture to a new size.

Size

Resolution of input video

void

ShaderPlugin.setupVideo


unload(): void

Reset plugin

Releases all resources and instances created in load().

void

ShaderPlugin.unload


update(result, stream): Promise<void>

Sealed

Update the image

Main method implementing webgl shader effect or filter. ShaderRenderer keeps track of the current iamge texture that will be be rendered. ShaderPlugin uses the current texture as input and writes results to ShaderPlugin#output. ShaderPlugin#output becomes new current texture of ShaderRenderer. This way all ShaderPlugins attached to renderer organize a chain of effects applied on top of each other. Method process() implements shader effect itself, it’s intended to be overridden by effect authors.

SegmentationResult

Results of video processing

HTMLCanvasElement

Captured video frame

Promise<void>

Promise resolving when update is finished

ShaderPlugin.update