DrawingUtils class

Helper class to visualize the result of a MediaPipe Vision task.

Signature:

export declare class DrawingUtils 

Constructors

Constructor Modifiers Description
(constructor)(gpuContext) Creates a new DrawingUtils class.
(constructor)(cpuContext, gpuContext) Creates a new DrawingUtils class.

Methods

Method Modifiers Description
clamp(x, x0, x1) static Restricts a number between two endpoints (order doesn't matter).
close() Frees all WebGL resources held by this class.
drawBoundingBox(boundingBox, style) Draws a bounding box.This method can only be used when DrawingUtils is initialized with a CanvasRenderingContext2D.
drawCategoryMask(mask, categoryToColorMap, background) Draws a category mask using the provided category-to-color mapping.
drawCategoryMask(mask, categoryToColorMap, background) Draws a category mask using the provided color array.
drawConfidenceMask(mask, defaultTexture, overlayTexture) Blends two images using the provided confidence mask.If you are using an ImageData or HTMLImageElement as your data source and drawing the result onto a WebGL2RenderingContext, this method uploads the image data to the GPU. For still image input that gets re-used every frame, you can reduce the cost of re-uploading these images by passing a HTMLCanvasElement instead.
drawConnectors(landmarks, connections, style) Draws lines between landmarks (given a connection graph).This method can only be used when DrawingUtils is initialized with a CanvasRenderingContext2D.
drawLandmarks(landmarks, style) Draws circles onto the provided landmarks.This method can only be used when DrawingUtils is initialized with a CanvasRenderingContext2D.
lerp(x, x0, x1, y0, y1) static Linearly interpolates a value between two points, clamping that value to the endpoints.

DrawingUtils.(constructor)

Creates a new DrawingUtils class.

Signature:

constructor(gpuContext: WebGL2RenderingContext);

Parameters

Parameter Type Description
gpuContext WebGL2RenderingContext The WebGL canvas rendering context to render into. If your Task is using a GPU delegate, the context must be obtained from its canvas (provided via setOptions({ canvas: .. })).

DrawingUtils.(constructor)

Creates a new DrawingUtils class.

Signature:

constructor(cpuContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, gpuContext?: WebGL2RenderingContext);

Parameters

Parameter Type Description
cpuContext CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D The 2D canvas rendering context to render into. If you are rendering GPU data you must also provide gpuContext to allow for data conversion.
gpuContext WebGL2RenderingContext A WebGL canvas that is used for GPU rendering and for converting GPU to CPU data. If your Task is using a GPU delegate, the context must be obtained from its canvas (provided via setOptions({ canvas: .. })).

DrawingUtils.clamp()

Restricts a number between two endpoints (order doesn't matter).

Signature:

static clamp(x