@mediapipe/tasks-vision 0.10.7 → 0.10.9-rc.20231208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,7 +66,7 @@ const vision = await FilesetResolver.forVisionTasks(
66
66
  "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm"
67
67
  );
68
68
  const gestureRecognizer = await GestureRecognizer.createFromModelPath(vision,
69
- "hhttps://storage.googleapis.com/mediapipe-models/gesture_recognizer/gesture_recognizer/float16/1/gesture_recognizer.task"
69
+ "https://storage.googleapis.com/mediapipe-models/gesture_recognizer/gesture_recognizer/float16/1/gesture_recognizer.task"
70
70
  );
71
71
  const image = document.getElementById("image") as HTMLImageElement;
72
72
  const recognitions = gestureRecognizer.recognize(image);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediapipe/tasks-vision",
3
- "version": "0.10.7",
3
+ "version": "0.10.9-rc.20231208",
4
4
  "description": "MediaPipe Vision Tasks",
5
5
  "main": "vision_bundle.cjs",
6
6
  "browser": "vision_bundle.mjs",
package/vision.d.ts CHANGED
@@ -103,6 +103,12 @@ export declare interface Category {
103
103
  displayName: string;
104
104
  }
105
105
 
106
+ /**
107
+ * A category to color mapping that uses either a map or an array to assign
108
+ * category indexes to RGBA colors.
109
+ */
110
+ export declare type CategoryToColorMap = Map<number, RGBAColor> | RGBAColor[];
111
+
106
112
  /** Classification results for a given classifier head. */
107
113
  export declare interface Classifications {
108
114
  /**
@@ -171,6 +177,9 @@ declare interface Connection {
171
177
  end: number;
172
178
  }
173
179
 
180
+ /** A color map with 22 classes. Used in our demos. */
181
+ export declare const DEFAULT_CATEGORY_TO_COLOR_MAP: number[][];
182
+
174
183
  /** Represents one detection by a detection task. */
175
184
  export declare interface Detection {
176
185
  /** A list of `Category` objects. */
@@ -218,9 +227,23 @@ export declare class DrawingUtils {
218
227
  /**
219
228
  * Creates a new DrawingUtils class.
220
229
  *
221
- * @param ctx The canvas to render onto.
230
+ * @param gpuContext The WebGL canvas rendering context to render into. If
231
+ * your Task is using a GPU delegate, the context must be obtained from
232
+ * its canvas (provided via `setOptions({ canvas: .. })`).
233
+ */
234
+ constructor(gpuContext: WebGL2RenderingContext);
235
+ /**
236
+ * Creates a new DrawingUtils class.
237
+ *
238
+ * @param cpuContext The 2D canvas rendering context to render into. If
239
+ * you are rendering GPU data you must also provide `gpuContext` to allow
240
+ * for data conversion.
241
+ * @param gpuContext A WebGL canvas that is used for GPU rendering and for
242
+ * converting GPU to CPU data. If your Task is using a GPU delegate, the
243
+ * context must be obtained from its canvas (provided via
244
+ * `setOptions({ canvas: .. })`).
222
245
  */
223
- constructor(ctx: CanvasRenderingContext2D);
246
+ constructor(cpuContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, gpuContext?: WebGL2RenderingContext);
224
247
  /**
225
248
  * Restricts a number between two endpoints (order doesn't matter).
226
249
  *
@@ -247,6 +270,9 @@ export declare class DrawingUtils {
247
270
  /**
248
271
  * Draws circles onto the provided landmarks.
249
272
  *
273
+ * This method can only be used when `DrawingUtils` is initialized with a
274
+ * `CanvasRenderingContext2D`.
275
+ *
250
276
  * @export
251
277
  * @param landmarks The landmarks to draw.
252
278
  * @param style The style to visualize the landmarks.
@@ -255,6 +281,9 @@ export declare class DrawingUtils {
255
281
  /**
256
282
  * Draws lines between landmarks (given a connection graph).
257
283
  *
284
+ * This method can only be used when `DrawingUtils` is initialized with a
285
+ * `CanvasRenderingContext2D`.
286
+ *
258
287
  * @export
259
288
  * @param landmarks The landmarks to draw.
260
289
  * @param connections The connections array that contains the start and the
@@ -265,11 +294,59 @@ export declare class DrawingUtils {
265
294
  /**
266
295
  * Draws a bounding box.
267
296
  *
297
+ * This method can only be used when `DrawingUtils` is initialized with a
298
+ * `CanvasRenderingContext2D`.
299
+ *
268
300
  * @export
269
301
  * @param boundingBox The bounding box to draw.
270
302
  * @param style The style to visualize the boundin box.
271
303
  */
272
304
  drawBoundingBox(boundingBox: BoundingBox, style?: DrawingOptions): void;
305
+ /**
306
+ * Draws a category mask using the provided category-to-color mapping.
307
+ *
308
+ * @export
309
+ * @param mask A category mask that was returned from a segmentation task.
310
+ * @param categoryToColorMap A map that maps category indices to RGBA
311
+ * values. You must specify a map entry for each category.
312
+ * @param background A color or image to use as the background. Defaults to
313
+ * black.
314
+ */
315
+ drawCategoryMask(mask: MPMask, categoryToColorMap: Map<number, RGBAColor>, background?: RGBAColor | ImageSource): void;
316
+ /**
317
+ * Draws a category mask using the provided color array.
318
+ *
319
+ * @export
320
+ * @param mask A category mask that was returned from a segmentation task.
321
+ * @param categoryToColorMap An array that maps indices to RGBA values. The
322
+ * array's indices must correspond to the category indices of the model
323
+ * and an entry must be provided for each category.
324
+ * @param background A color or image to use as the background. Defaults to
325
+ * black.
326
+ */
327
+ drawCategoryMask(mask: MPMask, categoryToColorMap: RGBAColor[], background?: RGBAColor | ImageSource): void;
328
+ /**
329
+ * Blends two images using the provided confidence mask.
330
+ *
331
+ * If you are using an `ImageData` or `HTMLImageElement` as your data source
332
+ * and drawing the result onto a `WebGL2RenderingContext`, this method uploads
333
+ * the image data to the GPU. For still image input that gets re-used every
334
+ * frame, you can reduce the cost of re-uploading these images by passing a
335
+ * `HTMLCanvasElement` instead.
336
+ *
337
+ * @export
338
+ * @param mask A confidence mask that was returned from a segmentation task.
339
+ * @param defaultTexture An image or a four-channel color that will be used
340
+ * when confidence values are low.
341
+ * @param overlayTexture An image or four-channel color that will be used when
342
+ * confidence values are high.
343
+ */
344
+ drawConfidenceMask(mask: MPMask, defaultTexture: RGBAColor | ImageSource, overlayTexture: RGBAColor | ImageSource): void;
345
+ /**
346
+ * Frees all WebGL resources held by this class.
347
+ * @export
348
+ */
349
+ close(): void;
273
350
  }
274
351
 
275
352
  /**
@@ -922,7 +999,7 @@ export declare interface GestureRecognizerOptions extends VisionTaskOptions {
922
999
  export declare interface GestureRecognizerResult {
923
1000
  /** Hand landmarks of detected hands. */
924
1001
  landmarks: NormalizedLandmark[][];
925
- /** Hand landmarks in world coordniates of detected hands. */
1002
+ /** Hand landmarks in world coordinates of detected hands. */
926
1003
  worldLandmarks: Landmark[][];
927
1004
  /** Handedness of detected hands. */
928
1005
  handedness: Category[][];
@@ -1880,6 +1957,7 @@ export declare class MPImage {
1880
1957
  * `close()` on the `MPMask` instance.
1881
1958
  */
1882
1959
  export declare class MPMask {
1960
+ readonly interpolateValues: boolean;
1883
1961
  /** Returns the canvas element that the mask is bound to. */
1884
1962
  readonly canvas: HTMLCanvasElement | OffscreenCanvas | undefined;
1885
1963
  /** Returns the width of the mask. */
@@ -2325,6 +2403,17 @@ export declare interface RegionOfInterest {
2325
2403
  scribble?: NormalizedKeypoint[];
2326
2404
  }
2327
2405
 
2406
+ /**
2407
+ * A four channel color with values for red, green, blue and alpha
2408
+ * respectively.
2409
+ */
2410
+ export declare type RGBAColor = [
2411
+ number,
2412
+ number,
2413
+ number,
2414
+ number
2415
+ ] | number[];
2416
+
2328
2417
  /**
2329
2418
  * The two running modes of a vision task.
2330
2419
  * 1) The image mode for processing single image inputs.