UNPKG

@mediapipe/tasks-vision

Version:

MediaPipe Vision Tasks

1,209 lines (1,182 loc) 117 kB
/** * Copyright 2022 The MediaPipe Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** Options to configure MediaPipe model loading and processing. */ declare interface BaseOptions_2 { /** * The model path to the model asset file. Only one of `modelAssetPath` or * `modelAssetBuffer` can be set. */ modelAssetPath?: string | undefined; /** * A buffer or stream reader containing the model asset. Only one of * `modelAssetPath` or `modelAssetBuffer` can be set. */ modelAssetBuffer?: Uint8Array | ReadableStreamDefaultReader | undefined; /** Overrides the default backend to use for the provided model. */ delegate?: "CPU" | "GPU" | undefined; } /** * Copyright 2023 The MediaPipe Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** An integer bounding box, axis aligned. */ export declare interface BoundingBox { /** The X coordinate of the top-left corner, in pixels. */ originX: number; /** The Y coordinate of the top-left corner, in pixels. */ originY: number; /** The width of the bounding box, in pixels. */ width: number; /** The height of the bounding box, in pixels. */ height: number; /** * Angle of rotation of the original non-rotated box around the top left * corner of the original non-rotated box, in clockwise degrees from the * horizontal. */ angle: number; } /** * A user-defined callback to take input data and map it to a custom output * value. */ export declare type Callback<I, O> = (input: I) => O; /** * Copyright 2022 The MediaPipe Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** A classification category. */ export declare interface Category { /** The probability score of this label category. */ score: number; /** The index of the category in the corresponding label file. */ index: number; /** * The label of this category object. Defaults to an empty string if there is * no category. */ categoryName: string; /** * The display name of the label, which may be translated for different * locales. For example, a label, "apple", may be translated into Spanish for * display purpose, so that the `display_name` is "manzana". Defaults to an * empty string if there is no display name. */ displayName: string; } /** * A category to color mapping that uses either a map or an array to assign * category indexes to RGBA colors. */ export declare type CategoryToColorMap = Map<number, RGBAColor> | RGBAColor[]; /** Classification results for a given classifier head. */ export declare interface Classifications { /** * The array of predicted categories, usually sorted by descending scores, * e.g., from high to low probability. */ categories: Category[]; /** * The index of the classifier head these categories refer to. This is * useful for multi-head models. */ headIndex: number; /** * The name of the classifier head, which is the corresponding tensor * metadata name. Defaults to an empty string if there is no such metadata. */ headName: string; } /** * Copyright 2022 The MediaPipe Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** Options to configure a MediaPipe Classifier Task. */ declare interface ClassifierOptions { /** * The locale to use for display names specified through the TFLite Model * Metadata, if any. Defaults to English. */ displayNamesLocale?: string | undefined; /** The maximum number of top-scored detection results to return. */ maxResults?: number | undefined; /** * Overrides the value provided in the model metadata. Results below this * value are rejected. */ scoreThreshold?: number | undefined; /** * Allowlist of category names. If non-empty, detection results whose category * name is not in this set will be filtered out. Duplicate or unknown category * names are ignored. Mutually exclusive with `categoryDenylist`. */ categoryAllowlist?: string[] | undefined; /** * Denylist of category names. If non-empty, detection results whose category * name is in this set will be filtered out. Duplicate or unknown category * names are ignored. Mutually exclusive with `categoryAllowlist`. */ categoryDenylist?: string[] | undefined; } /** A connection between two landmarks. */ declare interface Connection { start: number; end: number; } /** A color map with 22 classes. Used in our demos. */ export declare const DEFAULT_CATEGORY_TO_COLOR_MAP: number[][]; /** Represents one detection by a detection task. */ export declare interface Detection { /** A list of `Category` objects. */ categories: Category[]; /** The bounding box of the detected objects. */ boundingBox?: BoundingBox; /** * List of keypoints associated with the detection. Keypoints represent * interesting points related to the detection. For example, the keypoints * represent the eye, ear and mouth from face detection model. Or in the * template matching detection, e.g. KNIFT, they can represent the feature * points for template matching. Contains an empty list if no keypoints are * detected. */ keypoints: NormalizedKeypoint[]; } /** Detection results of a model. */ declare interface DetectionResult { /** A list of Detections. */ detections: Detection[]; } export { DetectionResult as FaceDetectorResult } export { DetectionResult as ObjectDetectorResult } /** * Options for customizing the drawing routines */ export declare interface DrawingOptions { /** The color that is used to draw the shape. Defaults to white. */ color?: string | CanvasGradient | CanvasPattern | Callback<LandmarkData, string | CanvasGradient | CanvasPattern>; /** * The color that is used to fill the shape. Defaults to `.color` (or black * if color is not set). */ fillColor?: string | CanvasGradient | CanvasPattern | Callback<LandmarkData, string | CanvasGradient | CanvasPattern>; /** The width of the line boundary of the shape. Defaults to 4. */ lineWidth?: number | Callback<LandmarkData, number>; /** The radius of location marker. Defaults to 6. */ radius?: number | Callback<LandmarkData, number>; } /** Helper class to visualize the result of a MediaPipe Vision task. */ export declare class DrawingUtils { /** * Creates a new DrawingUtils class. * * @param gpuContext 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: .. })`). */ constructor(gpuContext: WebGL2RenderingContext); /** * Creates a new DrawingUtils class. * * @param cpuContext The 2D canvas rendering context to render into. If * you are rendering GPU data you must also provide `gpuContext` to allow * for data conversion. * @param gpuContext 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: .. })`). */ constructor(cpuContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, gpuContext?: WebGL2RenderingContext); /** * Restricts a number between two endpoints (order doesn't matter). * * @export * @param x The number to clamp. * @param x0 The first boundary. * @param x1 The second boundary. * @return The clamped value. */ static clamp(x: number, x0: number, x1: number): number; /** * Linearly interpolates a value between two points, clamping that value to * the endpoints. * * @export * @param x The number to interpolate. * @param x0 The x coordinate of the start value. * @param x1 The x coordinate of the end value. * @param y0 The y coordinate of the start value. * @param y1 The y coordinate of the end value. * @return The interpolated value. */ static lerp(x: number, x0: number, x1: number, y0: number, y1: number): number; /** * Draws circles onto the provided landmarks. * * This method can only be used when `DrawingUtils` is initialized with a * `CanvasRenderingContext2D`. * * @export * @param landmarks The landmarks to draw. * @param style The style to visualize the landmarks. */ drawLandmarks(landmarks?: NormalizedLandmark[], style?: DrawingOptions): void; /** * Draws lines between landmarks (given a connection graph). * * This method can only be used when `DrawingUtils` is initialized with a * `CanvasRenderingContext2D`. * * @export * @param landmarks The landmarks to draw. * @param connections The connections array that contains the start and the * end indices for the connections to draw. * @param style The style to visualize the landmarks. */ drawConnectors(landmarks?: NormalizedLandmark[], connections?: Connection[], style?: DrawingOptions): void; /** * Draws a bounding box. * * This method can only be used when `DrawingUtils` is initialized with a * `CanvasRenderingContext2D`. * * @export * @param boundingBox The bounding box to draw. * @param style The style to visualize the bounding box. */ drawBoundingBox(boundingBox: BoundingBox, style?: DrawingOptions): void; /** * Draws a category mask using the provided category-to-color mapping. * * @export * @param mask A category mask that was returned from a segmentation task. * @param categoryToColorMap A map that maps category indices to RGBA * values. You must specify a map entry for each category. * @param background A color or image to use as the background. Defaults to * black. */ drawCategoryMask(mask: MPMask, categoryToColorMap: Map<number, RGBAColor>, background?: RGBAColor | ImageSource): void; /** * Draws a category mask using the provided color array. * * @export * @param mask A category mask that was returned from a segmentation task. * @param categoryToColorMap An array that maps indices to RGBA values. The * array's indices must correspond to the category indices of the model * and an entry must be provided for each category. * @param background A color or image to use as the background. Defaults to * black. */ drawCategoryMask(mask: MPMask, categoryToColorMap: RGBAColor[], background?: RGBAColor | ImageSource): void; /** * 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. * * @export * @param mask A confidence mask that was returned from a segmentation task. * @param defaultTexture An image or a four-channel color that will be used * when confidence values are low. * @param overlayTexture An image or four-channel color that will be used when * confidence values are high. */ drawConfidenceMask(mask: MPMask, defaultTexture: RGBAColor | ImageSource, overlayTexture: RGBAColor | ImageSource): void; /** * Frees all WebGL resources held by this class. * @export */ close(): void; } /** * Copyright 2022 The MediaPipe Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** Options to configure a MediaPipe Embedder Task */ declare interface EmbedderOptions { /** * Whether to normalize the returned feature vector with L2 norm. Use this * option only if the model does not already contain a native L2_NORMALIZATION * TF Lite Op. In most cases, this is already the case and L2 norm is thus * achieved through TF Lite inference. */ l2Normalize?: boolean | undefined; /** * Whether the returned embedding should be quantized to bytes via scalar * quantization. Embeddings are implicitly assumed to be unit-norm and * therefore any dimension is guaranteed to have a value in [-1.0, 1.0]. Use * the l2_normalize option if this is not the case. */ quantize?: boolean | undefined; } /** * Copyright 2022 The MediaPipe Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * List of embeddings with an optional timestamp. * * One and only one of the two 'floatEmbedding' and 'quantizedEmbedding' will * contain data, based on whether or not the embedder was configured to perform * scalar quantization. */ export declare interface Embedding { /** * Floating-point embedding. Empty if the embedder was configured to perform * scalar-quantization. */ floatEmbedding?: number[]; /** * Scalar-quantized embedding. Empty if the embedder was not configured to * perform scalar quantization. */ quantizedEmbedding?: Uint8Array; /** * The index of the classifier head these categories refer to. This is * useful for multi-head models. */ headIndex: number; /** * The name of the classifier head, which is the corresponding tensor * metadata name. */ headName: string; } /** Performs face detection on images. */ export declare class FaceDetector extends VisionTaskRunner { /** * Initializes the Wasm runtime and creates a new face detector from the * provided options. * * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param faceDetectorOptions The options for the FaceDetector. Note that * either a path to the model asset or a model buffer needs to be * provided (via `baseOptions`). */ static createFromOptions(wasmFileset: WasmFileset, faceDetectorOptions: FaceDetectorOptions): Promise<FaceDetector>; /** * Initializes the Wasm runtime and creates a new face detector based on the * provided model asset buffer. * * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetBuffer An array or a stream containing a binary * representation of the model. */ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<FaceDetector>; /** * Initializes the Wasm runtime and creates a new face detector based on the * path to the model asset. * * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetPath The path to the model asset. */ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<FaceDetector>; private constructor(); /** * Sets new options for the FaceDetector. * * Calling `setOptions()` with a subset of options only affects those options. * You can reset an option back to its default value by explicitly setting it * to `undefined`. * * @export * @param options The options for the FaceDetector. */ setOptions(options: FaceDetectorOptions): Promise<void>; /** * Performs face detection on the provided single image and waits * synchronously for the response. Only use this method when the * FaceDetector is created with running mode `image`. * * @export * @param image An image to process. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return A result containing the list of detected faces. */ detect(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): DetectionResult; /** * Performs face detection on the provided video frame and waits * synchronously for the response. Only use this method when the * FaceDetector is created with running mode `video`. * * @export * @param videoFrame A video frame to process. * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return A result containing the list of detected faces. */ detectForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): DetectionResult; } /** Options to configure the MediaPipe Face Detector Task */ export declare interface FaceDetectorOptions extends VisionTaskOptions { /** * The minimum confidence score for the face detection to be considered * successful. Defaults to 0.5. */ minDetectionConfidence?: number | undefined; /** * The minimum non-maximum-suppression threshold for face detection to be * considered overlapped. Defaults to 0.3. */ minSuppressionThreshold?: number | undefined; } /** * Performs face landmarks detection on images. * * This API expects a pre-trained face landmarker model asset bundle. */ export declare class FaceLandmarker extends VisionTaskRunner { /** * Initializes the Wasm runtime and creates a new `FaceLandmarker` from the * provided options. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param faceLandmarkerOptions The options for the FaceLandmarker. * Note that either a path to the model asset or a model buffer needs to * be provided (via `baseOptions`). */ static createFromOptions(wasmFileset: WasmFileset, faceLandmarkerOptions: FaceLandmarkerOptions): Promise<FaceLandmarker>; /** * Initializes the Wasm runtime and creates a new `FaceLandmarker` based on * the provided model asset buffer. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetBuffer An array or a stream containing a binary * representation of the model. */ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<FaceLandmarker>; /** * Initializes the Wasm runtime and creates a new `FaceLandmarker` based on * the path to the model asset. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetPath The path to the model asset. */ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<FaceLandmarker>; /** * Landmark connections to draw the connection between a face's lips. * @export * @nocollapse */ static FACE_LANDMARKS_LIPS: Connection[]; /** * Landmark connections to draw the connection between a face's left eye. * @export * @nocollapse */ static FACE_LANDMARKS_LEFT_EYE: Connection[]; /** * Landmark connections to draw the connection between a face's left eyebrow. * @export * @nocollapse */ static FACE_LANDMARKS_LEFT_EYEBROW: Connection[]; /** * Landmark connections to draw the connection between a face's left iris. * @export * @nocollapse */ static FACE_LANDMARKS_LEFT_IRIS: Connection[]; /** * Landmark connections to draw the connection between a face's right eye. * @export * @nocollapse */ static FACE_LANDMARKS_RIGHT_EYE: Connection[]; /** * Landmark connections to draw the connection between a face's right * eyebrow. * @export * @nocollapse */ static FACE_LANDMARKS_RIGHT_EYEBROW: Connection[]; /** * Landmark connections to draw the connection between a face's right iris. * @export * @nocollapse */ static FACE_LANDMARKS_RIGHT_IRIS: Connection[]; /** * Landmark connections to draw the face's oval. * @export * @nocollapse */ static FACE_LANDMARKS_FACE_OVAL: Connection[]; /** * Landmark connections to draw the face's contour. * @export * @nocollapse */ static FACE_LANDMARKS_CONTOURS: Connection[]; /** * Landmark connections to draw the face's tesselation. * @export * @nocollapse */ static FACE_LANDMARKS_TESSELATION: Connection[]; private constructor(); /** * Sets new options for this `FaceLandmarker`. * * Calling `setOptions()` with a subset of options only affects those options. * You can reset an option back to its default value by explicitly setting it * to `undefined`. * * @export * @param options The options for the face landmarker. */ setOptions(options: FaceLandmarkerOptions): Promise<void>; /** * Performs face landmarks detection on the provided single image and waits * synchronously for the response. Only use this method when the * FaceLandmarker is created with running mode `image`. * * @export * @param image An image to process. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return The detected face landmarks. */ detect(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): FaceLandmarkerResult; /** * Performs face landmarks detection on the provided video frame and waits * synchronously for the response. Only use this method when the * FaceLandmarker is created with running mode `video`. * * @export * @param videoFrame A video frame to process. * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return The detected face landmarks. */ detectForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): FaceLandmarkerResult; } /** Options to configure the MediaPipe FaceLandmarker Task */ export declare interface FaceLandmarkerOptions extends VisionTaskOptions { /** * The maximum number of faces can be detected by the FaceLandmarker. * Defaults to 1. */ numFaces?: number | undefined; /** * The minimum confidence score for the face detection to be considered * successful. Defaults to 0.5. */ minFaceDetectionConfidence?: number | undefined; /** * The minimum confidence score of face presence score in the face landmark * detection. Defaults to 0.5. */ minFacePresenceConfidence?: number | undefined; /** * The minimum confidence score for the face tracking to be considered * successful. Defaults to 0.5. */ minTrackingConfidence?: number | undefined; /** * Whether FaceLandmarker outputs face blendshapes classification. Face * blendshapes are used for rendering the 3D face model. */ outputFaceBlendshapes?: boolean | undefined; /** * Whether FaceLandmarker outputs facial transformation_matrix. Facial * transformation matrix is used to transform the face landmarks in canonical * face to the detected face, so that users can apply face effects on the * detected landmarks. */ outputFacialTransformationMatrixes?: boolean | undefined; } /** * Represents the face landmarks deection results generated by `FaceLandmarker`. */ export declare interface FaceLandmarkerResult { /** Detected face landmarks in normalized image coordinates. */ faceLandmarks: NormalizedLandmark[][]; /** Optional face blendshapes results. */ faceBlendshapes: Classifications[]; /** Optional facial transformation matrix. */ facialTransformationMatrixes: Matrix[]; } /** * Resolves the files required for the MediaPipe Task APIs. * * This class verifies whether SIMD is supported in the current environment and * loads the SIMD files only if support is detected. The returned filesets * require that the Wasm files are published without renaming. If this is not * possible, you can invoke the MediaPipe Tasks APIs using a manually created * `WasmFileset`. */ export declare class FilesetResolver { /** * Returns whether SIMD is supported in the current environment. * * If your environment requires custom locations for the MediaPipe Wasm files, * you can use `isSimdSupported()` to decide whether to load the SIMD-based * assets. Note that for ES6 Modules, SIMD is assumed to be always supported. * * @param useModule Whether to use ES6 Modules for the Wasm files. * @export * @return Whether SIMD support was detected in the current environment. */ static isSimdSupported(useModule?: boolean): Promise<boolean>; /** * Creates a fileset for the MediaPipe Audio tasks. * * @export * @param basePath An optional base path to specify the directory the Wasm * files should be loaded from. If not specified, the Wasm files are * loaded from the host's root directory. * @param useModule Whether to use ES6 Modules for the Wasm files. * @return A `WasmFileset` that can be used to initialize MediaPipe Audio * tasks. */ static forAudioTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>; /** * Creates a fileset for the MediaPipe GenAI tasks. * * @export * @param basePath An optional base path to specify the directory the Wasm * files should be loaded from. If not specified, the Wasm files are * loaded from the host's root directory. * @param useModule Whether to use ES6 Modules for the Wasm files. * @return A `WasmFileset` that can be used to initialize MediaPipe GenAI * tasks. */ static forGenAiTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>; /** * Creates a fileset for the MediaPipe Text tasks. * * @export * @param basePath An optional base path to specify the directory the Wasm * files should be loaded from. If not specified, the Wasm files are * loaded from the host's root directory. * @param useModule Whether to use ES6 Modules for the Wasm files. * @return A `WasmFileset` that can be used to initialize MediaPipe Text * tasks. */ static forTextTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>; /** * Creates a fileset for the MediaPipe Vision tasks. * * @export * @param basePath An optional base path to specify the directory the Wasm * files should be loaded from. If not specified, the Wasm files are * loaded from the host's root directory. * @param useModule Whether to use ES6 Modules for the Wasm files. * @return A `WasmFileset` that can be used to initialize MediaPipe Vision * tasks. */ static forVisionTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>; } /** Performs hand gesture recognition on images. */ export declare class GestureRecognizer extends VisionTaskRunner { /** * An array containing the pairs of hand landmark indices to be rendered with * connections. * @export * @nocollapse */ static HAND_CONNECTIONS: Connection[]; /** * Initializes the Wasm runtime and creates a new gesture recognizer from the * provided options. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param gestureRecognizerOptions The options for the gesture recognizer. * Note that either a path to the model asset or a model buffer needs to * be provided (via `baseOptions`). */ static createFromOptions(wasmFileset: WasmFileset, gestureRecognizerOptions: GestureRecognizerOptions): Promise<GestureRecognizer>; /** * Initializes the Wasm runtime and creates a new gesture recognizer based on * the provided model asset buffer. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetBuffer An array or a stream containing a binary * representation of the model. */ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<GestureRecognizer>; /** * Initializes the Wasm runtime and creates a new gesture recognizer based on * the path to the model asset. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetPath The path to the model asset. */ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<GestureRecognizer>; private constructor(); /** * Sets new options for the gesture recognizer. * * Calling `setOptions()` with a subset of options only affects those options. * You can reset an option back to its default value by explicitly setting it * to `undefined`. * * @export * @param options The options for the gesture recognizer. */ setOptions(options: GestureRecognizerOptions): Promise<void>; /** * Performs gesture recognition on the provided single image and waits * synchronously for the response. Only use this method when the * GestureRecognizer is created with running mode `image`. * * @export * @param image A single image to process. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return The detected gestures. */ recognize(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): GestureRecognizerResult; /** * Performs gesture recognition on the provided video frame and waits * synchronously for the response. Only use this method when the * GestureRecognizer is created with running mode `video`. * * @export * @param videoFrame A video frame to process. * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return The detected gestures. */ recognizeForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): GestureRecognizerResult; } /** Options to configure the MediaPipe Gesture Recognizer Task */ export declare interface GestureRecognizerOptions extends VisionTaskOptions { /** * The maximum number of hands can be detected by the GestureRecognizer. * Defaults to 1. */ numHands?: number | undefined; /** * The minimum confidence score for the hand detection to be considered * successful. Defaults to 0.5. */ minHandDetectionConfidence?: number | undefined; /** * The minimum confidence score of hand presence score in the hand landmark * detection. Defaults to 0.5. */ minHandPresenceConfidence?: number | undefined; /** * The minimum confidence score for the hand tracking to be considered * successful. Defaults to 0.5. */ minTrackingConfidence?: number | undefined; /** * Sets the optional `ClassifierOptions` controlling the canned gestures * classifier, such as score threshold, allow list and deny list of gestures. * The categories for canned gesture * classifiers are: ["None", "Closed_Fist", "Open_Palm", "Pointing_Up", * "Thumb_Down", "Thumb_Up", "Victory", "ILoveYou"] */ cannedGesturesClassifierOptions?: ClassifierOptions | undefined; /** * Options for configuring the custom gestures classifier, such as score * threshold, allow list and deny list of gestures. */ customGesturesClassifierOptions?: ClassifierOptions | undefined; } /** * Represents the gesture recognition results generated by `GestureRecognizer`. */ export declare interface GestureRecognizerResult { /** Hand landmarks of detected hands. */ landmarks: NormalizedLandmark[][]; /** Hand landmarks in world coordinates of detected hands. */ worldLandmarks: Landmark[][]; /** Handedness of detected hands. */ handedness: Category[][]; /** * Handedness of detected hands. * @deprecated Use `.handedness` instead. */ handednesses: Category[][]; /** * Recognized hand gestures of detected hands. Note that the index of the * gesture is always -1, because the raw indices from multiple gesture * classifiers cannot consolidate to a meaningful index. */ gestures: Category[][]; } /** Performs hand landmarks detection on images. */ export declare class HandLandmarker extends VisionTaskRunner { /** * An array containing the pairs of hand landmark indices to be rendered with * connections. * @export * @nocollapse */ static HAND_CONNECTIONS: Connection[]; /** * Initializes the Wasm runtime and creates a new `HandLandmarker` from the * provided options. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param handLandmarkerOptions The options for the HandLandmarker. * Note that either a path to the model asset or a model buffer needs to * be provided (via `baseOptions`). */ static createFromOptions(wasmFileset: WasmFileset, handLandmarkerOptions: HandLandmarkerOptions): Promise<HandLandmarker>; /** * Initializes the Wasm runtime and creates a new `HandLandmarker` based on * the provided model asset buffer. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetBuffer An array or a stream containing a binary * representation of the model. */ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<HandLandmarker>; /** * Initializes the Wasm runtime and creates a new `HandLandmarker` based on * the path to the model asset. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetPath The path to the model asset. */ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<HandLandmarker>; private constructor(); /** * Sets new options for this `HandLandmarker`. * * Calling `setOptions()` with a subset of options only affects those options. * You can reset an option back to its default value by explicitly setting it * to `undefined`. * * @export * @param options The options for the hand landmarker. */ setOptions(options: HandLandmarkerOptions): Promise<void>; /** * Performs hand landmarks detection on the provided single image and waits * synchronously for the response. Only use this method when the * HandLandmarker is created with running mode `image`. * * @export * @param image An image to process. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return The detected hand landmarks. */ detect(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): HandLandmarkerResult; /** * Performs hand landmarks detection on the provided video frame and waits * synchronously for the response. Only use this method when the * HandLandmarker is created with running mode `video`. * * @export * @param videoFrame A video frame to process. * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @return The detected hand landmarks. */ detectForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): HandLandmarkerResult; } /** Options to configure the MediaPipe HandLandmarker Task */ export declare interface HandLandmarkerOptions extends VisionTaskOptions { /** * The maximum number of hands can be detected by the HandLandmarker. * Defaults to 1. */ numHands?: number | undefined; /** * The minimum confidence score for the hand detection to be considered * successful. Defaults to 0.5. */ minHandDetectionConfidence?: number | undefined; /** * The minimum confidence score of hand presence score in the hand landmark * detection. Defaults to 0.5. */ minHandPresenceConfidence?: number | undefined; /** * The minimum confidence score for the hand tracking to be considered * successful. Defaults to 0.5. */ minTrackingConfidence?: number | undefined; } /** * Represents the hand landmarks deection results generated by `HandLandmarker`. */ export declare interface HandLandmarkerResult { /** Hand landmarks of detected hands. */ landmarks: NormalizedLandmark[][]; /** Hand landmarks in world coordinates of detected hands. */ worldLandmarks: Landmark[][]; /** * Handedness of detected hands. * @deprecated Use `.handedness` instead. */ handednesses: Category[][]; /** Handedness of detected hands. */ handedness: Category[][]; } /** Performs holistic landmarks detection on images. */ export declare class HolisticLandmarker extends VisionTaskRunner { /** * An array containing the pairs of hand landmark indices to be rendered with * connections. * @export * @nocollapse */ static HAND_CONNECTIONS: Connection[]; /** * An array containing the pairs of pose landmark indices to be rendered with * connections. * @export * @nocollapse */ static POSE_CONNECTIONS: Connection[]; /** * Landmark connections to draw the connection between a face's lips. * @export * @nocollapse */ static FACE_LANDMARKS_LIPS: Connection[]; /** * Landmark connections to draw the connection between a face's left eye. * @export * @nocollapse */ static FACE_LANDMARKS_LEFT_EYE: Connection[]; /** * Landmark connections to draw the connection between a face's left eyebrow. * @export * @nocollapse */ static FACE_LANDMARKS_LEFT_EYEBROW: Connection[]; /** * Landmark connections to draw the connection between a face's left iris. * @export * @nocollapse */ static FACE_LANDMARKS_LEFT_IRIS: Connection[]; /** * Landmark connections to draw the connection between a face's right eye. * @export * @nocollapse */ static FACE_LANDMARKS_RIGHT_EYE: Connection[]; /** * Landmark connections to draw the connection between a face's right * eyebrow. * @export * @nocollapse */ static FACE_LANDMARKS_RIGHT_EYEBROW: Connection[]; /** * Landmark connections to draw the connection between a face's right iris. * @export * @nocollapse */ static FACE_LANDMARKS_RIGHT_IRIS: Connection[]; /** * Landmark connections to draw the face's oval. * @export * @nocollapse */ static FACE_LANDMARKS_FACE_OVAL: Connection[]; /** * Landmark connections to draw the face's contour. * @export * @nocollapse */ static FACE_LANDMARKS_CONTOURS: Connection[]; /** * Landmark connections to draw the face's tesselation. * @export * @nocollapse */ static FACE_LANDMARKS_TESSELATION: Connection[]; /** * Initializes the Wasm runtime and creates a new `HolisticLandmarker` from * the provided options. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param holisticLandmarkerOptions The options for the HolisticLandmarker. * Note that either a path to the model asset or a model buffer needs to * be provided (via `baseOptions`). */ static createFromOptions(wasmFileset: WasmFileset, holisticLandmarkerOptions: HolisticLandmarkerOptions): Promise<HolisticLandmarker>; /** * Initializes the Wasm runtime and creates a new `HolisticLandmarker` based * on the provided model asset buffer. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetBuffer An array or a stream containing a binary * representation of the model. */ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<HolisticLandmarker>; /** * Initializes the Wasm runtime and creates a new `HolisticLandmarker` based * on the path to the model asset. * @export * @param wasmFileset A configuration object that provides the location of the * Wasm binary and its loader. * @param modelAssetPath The path to the model asset. */ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<HolisticLandmarker>; private constructor(); /** * Sets new options for this `HolisticLandmarker`. * * Calling `setOptions()` with a subset of options only affects those options. * You can reset an option back to its default value by explicitly setting it * to `undefined`. * * @export * @param options The options for the holistic landmarker. */ setOptions(options: HolisticLandmarkerOptions): Promise<void>; /** * Performs holistic landmarks detection on the provided single image and * invokes the callback with the response. The method returns synchronously * once the callback returns. Only use this method when the HolisticLandmarker * is created with running mode `image`. * * @export * @param image An image to process. * @param callback The callback that is invoked with the result. The * lifetime of the returned masks is only guaranteed for the duration of * the callback. */ detect(image: ImageSource, callback: HolisticLandmarkerCallback): void; /** * Performs holistic landmarks detection on the provided single image and * invokes the callback with the response. The method returns synchronously * once the callback returns. Only use this method when the HolisticLandmarker * is created with running mode `image`. * * @export * @param image An image to process. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. * @param callback The callback that is invoked with the result. The * lifetime of the returned masks is only guaranteed for the duration of * the callback. */ detect(image: ImageSource, imageProcessingOptions: ImageProcessingOptions, callback: HolisticLandmarkerCallback): void; /** * Performs holistic landmarks detection on the provided single image and * waits synchronously for the response. This method creates a copy of the * resulting masks and should not be used in high-throughput applications. * Only use this method when the HolisticLandmarker is created with running * mode `image`. * * @export * @param image An image to process. * @return The landmarker result. Any masks are copied to avoid lifetime * limits. * @return The detected pose landmarks. */ detect(image: ImageSource): HolisticLandmarkerResult; /** * Performs holistic landmarks detection on the provided single image and * waits synchronously for the response. This method creates a copy of the * resulting masks and should not be used in high-throughput applications. * Only use this method when the HolisticLandmarker is created with running * mode `image`. * * @export * @param image An image to process. * @return The landmarker result. Any masks are copied to avoid lifetime * limits. * @return The detected pose landmarks. */ detect(image: ImageSource, imageProcessingOptions: ImageProcessingOptions): HolisticLandmarkerResult; /** * Performs holistic landmarks detection on the provided video frame and * invokes the callback with the response. The method returns synchronously * once the callback returns. Only use