@mediapipe/tasks-vision 0.1.0-alpha-7 → 0.1.0-alpha-8

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
@@ -2,6 +2,22 @@
2
2
 
3
3
  This package contains the vision tasks for MediaPipe.
4
4
 
5
+ ## Face Detection
6
+
7
+ The MediaPipe Face Detector task lets you detect the presence and location of
8
+ faces within images or videos.
9
+
10
+ ```
11
+ const vision = await FilesetResolver.forVisionTasks(
12
+ "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm"
13
+ );
14
+ const faceDetector = await FaceDetector.createFromModelPath(vision,
15
+ "https://storage.googleapis.com/mediapipe-tasks/object_detector/efficientdet_lite0_uint8.tflite"
16
+ );
17
+ const image = document.getElementById("image") as HTMLImageElement;
18
+ const detections = faceDetector.detect(image);
19
+ ```
20
+
5
21
  ## Face Landmark Detection
6
22
 
7
23
  The MediaPipe Face Landmarker task lets you detect the landmarks of faces in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediapipe/tasks-vision",
3
- "version": "0.1.0-alpha-7",
3
+ "version": "0.1.0-alpha-8",
4
4
  "description": "MediaPipe Vision Tasks",
5
5
  "main": "vision_bundle.js",
6
6
  "author": "mediapipe@google.com",
package/vision.d.ts CHANGED
@@ -29,6 +29,21 @@ declare interface BaseOptions_2 {
29
29
  delegate?: "CPU" | "GPU" | undefined;
30
30
  }
31
31
 
32
+ /**
33
+ * Copyright 2023 The MediaPipe Authors. All Rights Reserved.
34
+ *
35
+ * Licensed under the Apache License, Version 2.0 (the "License");
36
+ * you may not use this file except in compliance with the License.
37
+ * You may obtain a copy of the License at
38
+ *
39
+ * http://www.apache.org/licenses/LICENSE-2.0
40
+ *
41
+ * Unless required by applicable law or agreed to in writing, software
42
+ * distributed under the License is distributed on an "AS IS" BASIS,
43
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44
+ * See the License for the specific language governing permissions and
45
+ * limitations under the License.
46
+ */
32
47
  /** An integer bounding box, axis aligned. */
33
48
  export declare interface BoundingBox {
34
49
  /** The X coordinate of the top-left corner, in pixels. */
@@ -138,13 +153,29 @@ declare interface ClassifierOptions {
138
153
  categoryDenylist?: string[] | undefined;
139
154
  }
140
155
 
141
- /** Represents one object detected by the `ObjectDetector`. */
156
+ /** Represents one detection by a detection task. */
142
157
  export declare interface Detection {
143
158
  /** A list of `Category` objects. */
144
159
  categories: Category[];
145
160
  /** The bounding box of the detected objects. */
146
161
  boundingBox?: BoundingBox;
162
+ /**
163
+ * Optional list of keypoints associated with the detection. Keypoints
164
+ * represent interesting points related to the detection. For example, the
165
+ * keypoints represent the eye, ear and mouth from face detection model. Or
166
+ * in the template matching detection, e.g. KNIFT, they can represent the
167
+ * feature points for template matching.
168
+ */
169
+ keypoints?: NormalizedKeypoint[];
170
+ }
171
+
172
+ /** Detection results of a model. */
173
+ declare interface DetectionResult {
174
+ /** A list of Detections. */
175
+ detections: Detection[];
147
176
  }
177
+ export { DetectionResult as FaceDetectorResult }
178
+ export { DetectionResult as ObjectDetectorResult }
148
179
 
149
180
  /**
150
181
  * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
@@ -224,6 +255,84 @@ export declare interface Embedding {
224
255
  headName: string;
225
256
  }
226
257
 
258
+ /** Performs face detection on images. */
259
+ export declare class FaceDetector extends VisionTaskRunner {
260
+ /**
261
+ * Initializes the Wasm runtime and creates a new face detector from the
262
+ * provided options.
263
+ * @param wasmFileset A configuration object that provides the location of the
264
+ * Wasm binary and its loader.
265
+ * @param faceDetectorOptions The options for the FaceDetector. Note that
266
+ * either a path to the model asset or a model buffer needs to be
267
+ * provided (via `baseOptions`).
268
+ */
269
+ static createFromOptions(wasmFileset: WasmFileset, faceDetectorOptions: FaceDetectorOptions): Promise<FaceDetector>;
270
+ /**
271
+ * Initializes the Wasm runtime and creates a new face detector based on the
272
+ * provided model asset buffer.
273
+ * @param wasmFileset A configuration object that provides the location of the
274
+ * Wasm binary and its loader.
275
+ * @param modelAssetBuffer A binary representation of the model.
276
+ */
277
+ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array): Promise<FaceDetector>;
278
+ /**
279
+ * Initializes the Wasm runtime and creates a new face detector based on the
280
+ * path to the model asset.
281
+ * @param wasmFileset A configuration object that provides the location of the
282
+ * Wasm binary and its loader.
283
+ * @param modelAssetPath The path to the model asset.
284
+ */
285
+ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<FaceDetector>;
286
+ private constructor();
287
+ /**
288
+ * Sets new options for the FaceDetector.
289
+ *
290
+ * Calling `setOptions()` with a subset of options only affects those options.
291
+ * You can reset an option back to its default value by explicitly setting it
292
+ * to `undefined`.
293
+ *
294
+ * @param options The options for the FaceDetector.
295
+ */
296
+ setOptions(options: FaceDetectorOptions): Promise<void>;
297
+ /**
298
+ * Performs face detection on the provided single image and waits
299
+ * synchronously for the response. Only use this method when the
300
+ * FaceDetector is created with running mode `image`.
301
+ *
302
+ * @param image An image to process.
303
+ * @param imageProcessingOptions the `ImageProcessingOptions` specifying how
304
+ * to process the input image before running inference.
305
+ * @return A result containing the list of detected faces.
306
+ */
307
+ detect(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): DetectionResult;
308
+ /**
309
+ * Performs face detection on the provided video frame and waits
310
+ * synchronously for the response. Only use this method when the
311
+ * FaceDetector is created with running mode `video`.
312
+ *
313
+ * @param videoFrame A video frame to process.
314
+ * @param timestamp The timestamp of the current frame, in ms.
315
+ * @param imageProcessingOptions the `ImageProcessingOptions` specifying how
316
+ * to process the input image before running inference.
317
+ * @return A result containing the list of detected faces.
318
+ */
319
+ detectForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): DetectionResult;
320
+ }
321
+
322
+ /** Options to configure the MediaPipe Face Detector Task */
323
+ export declare interface FaceDetectorOptions extends VisionTaskOptions {
324
+ /**
325
+ * The minimum confidence score for the face detection to be considered
326
+ * successful. Defaults to 0.5.
327
+ */
328
+ minDetectionConfidence?: number | undefined;
329
+ /**
330
+ * The minimum non-maximum-suppression threshold for face detection to be
331
+ * considered overlapped. Defaults to 0.3.
332
+ */
333
+ minSuppressionThreshold?: number | undefined;
334
+ }
335
+
227
336
  /**
228
337
  * Performs face landmarks detection on images.
229
338
  *
@@ -1254,7 +1363,7 @@ export declare interface Landmark {
1254
1363
  * See the License for the specific language governing permissions and
1255
1364
  * limitations under the License.
1256
1365
  */
1257
- /** A two-dimenionsal matrix. */
1366
+ /** A two-dimensional matrix. */
1258
1367
  declare interface Matrix {
1259
1368
  /** The number of rows. */
1260
1369
  rows: number;
@@ -1372,9 +1481,9 @@ export declare class ObjectDetector extends VisionTaskRunner {
1372
1481
  * @param image An image to process.
1373
1482
  * @param imageProcessingOptions the `ImageProcessingOptions` specifying how
1374
1483
  * to process the input image before running inference.
1375
- * @return The list of detected objects
1484
+ * @return A result containing a list of detected objects.
1376
1485
  */
1377
- detect(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): Detection[];
1486
+ detect(image: ImageSource, imageProcessingOptions?: ImageProcessingOptions): DetectionResult;
1378
1487
  /**
1379
1488
  * Performs object detection on the provided video frame and waits
1380
1489
  * synchronously for the response. Only use this method when the
@@ -1384,9 +1493,9 @@ export declare class ObjectDetector extends VisionTaskRunner {
1384
1493
  * @param timestamp The timestamp of the current frame, in ms.
1385
1494
  * @param imageProcessingOptions the `ImageProcessingOptions` specifying how
1386
1495
  * to process the input image before running inference.
1387
- * @return The list of detected objects
1496
+ * @return A result containing a list of detected objects.
1388
1497
  */
1389
- detectForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): Detection[];
1498
+ detectForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions?: ImageProcessingOptions): DetectionResult;
1390
1499
  }
1391
1500
 
1392
1501
  /** Options to configure the MediaPipe Object Detector Task */
@@ -1424,7 +1533,7 @@ declare type RunningMode = "IMAGE" | "VIDEO";
1424
1533
  /**
1425
1534
  * The segmentation tasks return the segmentation either as a WebGLTexture (when
1426
1535
  * the output is on GPU) or as a typed JavaScript arrays for CPU-based
1427
- * category or confidence masks. `Uint8ClampedArray`s are used to represend
1536
+ * category or confidence masks. `Uint8ClampedArray`s are used to represent
1428
1537
  * CPU-based category masks and `Float32Array`s are used for CPU-based
1429
1538
  * confidence masks.
1430
1539
  */
@@ -1457,7 +1566,7 @@ declare interface TaskRunnerOptions {
1457
1566
  declare interface VisionTaskOptions extends TaskRunnerOptions {
1458
1567
  /**
1459
1568
  * The canvas element to bind textures to. This has to be set for GPU
1460
- * processing. The task will initialize a WebGL context and throw an eror if
1569
+ * processing. The task will initialize a WebGL context and throw an error if
1461
1570
  * this fails (e.g. if you have already initialized a different type of
1462
1571
  * context).
1463
1572
  */