BodyPatchPlugin
Body 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.
Extends
Constructors
new BodyPatchPlugin()
new BodyPatchPlugin(
thresh
,radius
):BodyPatchPlugin
Constructor
Parameters
• thresh: number
= 0.55
Foreground threshold
• radius: number
= 512
Radius of foreground search
Returns
Overrides
Properties
fragSrc?
protected
optional
fragSrc:string
Code of fragment shader (copy shader by default)
Inherited from
inputs?
protected
optional
inputs:string
[]
Shader texture inputs (names of sampler uniforms)
Inherited from
loaded
loaded:
boolean
Loaded state
Inherited from
ordinal
ordinal:
number
Ordinal number
Inherited from
renderer?
protected
optional
renderer:Renderer
<SegmentationResult
>
Renderer loaded the plugin
Inherited from
shader?
protected
optional
shader:ShaderProgram
Rendering shader
Inherited from
shaderCtx?
protected
optional
shaderCtx:WebGL2RenderingContext
Rendering context
Inherited from
size
protected
size:Size
Image size
Inherited from
uniforms?
protected
optional
uniforms:object
Shader uniforms as name-type map object
Index Signature
[key
: string
]: UniformType
Inherited from
vertSrc?
protected
optional
vertSrc:string
Vertex shader source (copy shader by default)
Inherited from
Methods
dispose()
dispose():
void
Dispose video plugin
Returns
void
Inherited from
load()
load(
renderer
):Promise
<void
>
Initialize plugin
Initializes resources required for shader effect. Acquires webgl context of the main webgl renderer. Basic implementation creates and compiles rendering program for shaders provided to plugin’s constructor. Overridden by derived classes for particular effect.
Parameters
• renderer: Renderer
<SegmentationResult
>
Renderer this plugin is attached to
Returns
Promise
<void
>
Promise resolving when initialization is finished
Inherited from
process()
process(
result
,input
):Promise
<boolean
>
Process the image
Patches (inpaints) foreground image pixels according to provided segmentation mask.
Parameters
• result: SegmentationResult
Results of video processing
• input: WebGLTexture
Current image texture
Returns
Promise
<boolean
>
True on success, false otherwise
Overrides
setupCamera()
setupCamera(
ratio
,angle
):void
Set camera parameters
Could be overridden to adjust plugin’s pipeline.
Parameters
• ratio: number
Aspect ration of input video
• angle: number
Vertical field of view in radians
Returns
void
Inherited from
setupVideo()
setupVideo(
size
):void
Set video size
Adjusts shader and texture to a new size.
Parameters
• size: Size
Resolution of input video
Returns
void
Inherited from
unload()
unload():
void
Reset plugin
Releases all resources and instances created in load(). Overridden by derived classes for particular effect.
Returns
void
Inherited from
update()
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.
Parameters
• result: SegmentationResult
Results of video processing
• stream: HTMLCanvasElement
Captured video frame
Returns
Promise
<void
>
Promise resolving when update is finished