33// This software is released under the MIT License.
44// https://opensource.org/licenses/MIT
55
6- /* eslint prefer-destructuring: ["error", {AssignmentExpression: {array: false}}] */
7- /* eslint no-await-in-loop: "off" */
8-
96/*
107 * Facemesh: Facial landmark detection in the browser
118 * Ported and integrated from all the hard work by: https://github.com/tensorflow/tfjs-models/tree/master/facemesh
@@ -19,14 +16,17 @@ import callCallback from "../utils/callcallback";
1916class Facemesh extends EventEmitter {
2017 /**
2118 * Create Facemesh.
22- * @param {HTMLVideoElement } video - An HTMLVideoElement.
23- * @param {object } options - An object with options.
24- * @param {function } callback - A callback to be called when the model is ready.
19+ * @param {HTMLVideoElement } [ video] - An HTMLVideoElement.
20+ * @param {object } [ options] - An object with options.
21+ * @param {function } [ callback] - A callback to be called when the model is ready.
2522 */
2623 constructor ( video , options , callback ) {
2724 super ( ) ;
2825
2926 this . video = video ;
27+ /**
28+ * @type {null | facemeshCore.FaceMesh }
29+ */
3030 this . model = null ;
3131 this . modelReady = false ;
3232 this . config = options ;
@@ -49,18 +49,21 @@ class Facemesh extends EventEmitter {
4949 } ;
5050 } ) ;
5151 }
52-
53- this . predict ( ) ;
52+ if ( this . video ) {
53+ this . predict ( ) ;
54+ }
5455
5556 return this ;
5657 }
5758
5859 /**
59- * Load the model and set it to this.model
60- * @return {this } the Facemesh model.
60+ * @return {Promise<facemeshCore.AnnotatedPrediction[]> } an array of predictions.
6161 */
6262 async predict ( inputOr , callback ) {
6363 const input = this . getInput ( inputOr ) ;
64+ if ( ! input ) {
65+ throw new Error ( "No input image found." ) ;
66+ }
6467 const { flipHorizontal } = this . config ;
6568 const predictions = await this . model . estimateFaces ( input , flipHorizontal ) ;
6669 const result = predictions ;
0 commit comments