11
11
* Ported and integrated from all the hard work by: https://github.com/tensorflow/tfjs-models/tree/master/body-pix
12
12
*/
13
13
14
+ // @ts -check
14
15
import * as tf from '@tensorflow/tfjs' ;
15
16
import * as bp from '@tensorflow-models/body-pix' ;
16
17
import callCallback from '../utils/callcallback' ;
@@ -50,7 +51,7 @@ class BodyPix {
50
51
51
52
/**
52
53
* Load the model and set it to this.model
53
- * @return {this } the BodyPix model.
54
+ * @return {Promise<Object> } the BodyPix model.
54
55
*/
55
56
async loadModel ( ) {
56
57
this . model = await bp . load ( this . config . multiplier ) ;
@@ -60,7 +61,7 @@ class BodyPix {
60
61
61
62
/**
62
63
* Returns an rgb array
63
- * @param {Object } a p5.Color obj
64
+ * @param {Object } p5ColorObj - a p5.Color obj
64
65
* @return {Array } an [r,g,b] array
65
66
*/
66
67
/* eslint class-methods-use-this: "off" */
@@ -83,7 +84,7 @@ class BodyPix {
83
84
84
85
/**
85
86
* Returns a bodyPartsSpec object
86
- * @param {Array } an array of [r,g,b] colors
87
+ * @param {Array } colorOptions - an array of [r,g,b] colors
87
88
* @return {object } an object with the bodyParts by color and id
88
89
*/
89
90
/* eslint class-methods-use-this: "off" */
@@ -107,11 +108,11 @@ class BodyPix {
107
108
108
109
/**
109
110
* Segments the image with partSegmentation, return result object
110
- * @param {HTMLImageElement | HTMLCanvasElement | object | function | number } imageToSegment -
111
+ * @param {HTMLImageElement | HTMLCanvasElement | object | function | number } imgToSegment -
111
112
* takes any of the following params
112
113
* @param {object } segmentationOptions - config params for the segmentation
113
114
* includes outputStride, segmentationThreshold
114
- * @return {Object } a result object with image, raw, bodyParts
115
+ * @return {Promise< Object> } a result object with image, raw, bodyParts
115
116
*/
116
117
async segmentWithPartsInternal ( imgToSegment , segmentationOptions ) {
117
118
// estimatePartSegmentation
@@ -220,7 +221,7 @@ class BodyPix {
220
221
* @param {object } configOrCallback - config params for the segmentation
221
222
* includes palette, outputStride, segmentationThreshold
222
223
* @param {function } cb - a callback function that handles the results of the function.
223
- * @return {function } a promise or the results of a given callback, cb.
224
+ * @return {Promise<Object> } a promise or the results of a given callback, cb.
224
225
*/
225
226
async segmentWithParts ( optionsOrCallback , configOrCallback , cb ) {
226
227
let imgToSegment = this . video ;
@@ -268,11 +269,11 @@ class BodyPix {
268
269
269
270
/**
270
271
* Segments the image with personSegmentation, return result object
271
- * @param {HTMLImageElement | HTMLCanvasElement | object | function | number } imageToSegment -
272
+ * @param {HTMLImageElement | HTMLCanvasElement | object | function | number } imgToSegment -
272
273
* takes any of the following params
273
274
* @param {object } segmentationOptions - config params for the segmentation
274
275
* includes outputStride, segmentationThreshold
275
- * @return {Object } a result object with maskBackground, maskPerson, raw
276
+ * @return {Promise< Object> } a result object with maskBackground, maskPerson, raw
276
277
*/
277
278
async segmentInternal ( imgToSegment , segmentationOptions ) {
278
279
@@ -372,12 +373,12 @@ class BodyPix {
372
373
373
374
/**
374
375
* Segments the image with personSegmentation
375
- * @param {HTMLImageElement | HTMLCanvasElement | object | function | number } optionsOrCallback -
376
+ * @param {HTMLVideoElement | HTMLImageElement | HTMLCanvasElement | object | function | number } optionsOrCallback -
376
377
* takes any of the following params
377
378
* @param {object } configOrCallback - config params for the segmentation
378
379
* includes outputStride, segmentationThreshold
379
380
* @param {function } cb - a callback function that handles the results of the function.
380
- * @return {function } a promise or the results of a given callback, cb.
381
+ * @return {Promise<Object> } a promise or the results of a given callback, cb.
381
382
*/
382
383
async segment ( optionsOrCallback , configOrCallback , cb ) {
383
384
let imgToSegment = this . video ;
@@ -424,6 +425,13 @@ class BodyPix {
424
425
425
426
}
426
427
428
+ /**
429
+ *
430
+ * @param {Object | Function } videoOrOptionsOrCallback
431
+ * @param {Object | Function } optionsOrCallback
432
+ * @param {Function } cb
433
+ * @returns {Promise<Object> | Function }
434
+ */
427
435
const bodyPix = ( videoOrOptionsOrCallback , optionsOrCallback , cb ) => {
428
436
let video ;
429
437
let options = { } ;
0 commit comments