loadRecognition(models = null) {
         const labels = models.labels || [];
         const images = models.images || [];
         const sampleSize = models.sampleSize || 0;

        // return a promise that loads all the images and fetches their descriptors
        return Promise.all(

            // for each label get the descriptors based on the model image
            labels.map(async label => {

                const descriptors = [];
                var url;

                // iterate through all the model images in the folder (there are 6 right now and this number should be changed if more pics need to be added)
                for (let i = 1; i <= sampleSize; i++) {

                    url =  images.length > 0 ? images[i-1] : env.home + 'public/' + env.request.uri + `/recognition/${label}/${i}.png`;

                    // fetch the images from the model
                    const img = await faceapi.fetchImage(url);


                    // detect the single face from the image
                    const detections = await faceapi.detectSingleFace(img, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptor();

                    // push the descriptiors from each image detection onto the decriptor collections that will be needed
                    if (detections && detections.descriptor) {
                        descriptors.push(detections.descriptor);
                    };
                }

                return new faceapi.LabeledFaceDescriptors(label, descriptors);
            })
        );

    }
/* 
     * Method that loads models for recognition
     *
     * @models: Object. Default null. When specified the recognitions are loaded from the images provided as opposed to the ones in storage
     * @output: return promise with face descriptors of the models to be recognized
     */
Method that loads models for recognition
@models: Object. Default null. When specified the recognitions are loaded from the images provided as opposed to the ones in storage
@output: return promise with face descriptors of the models to be recognized
Method that loads models for recognition @models : Object . Default null . When specified the recognitions are loaded from the images provided as opposed to the ones in storage @output : return promise with face descriptors of the models to be recognized
loadRecognition(models = null) {
         const labels = models.labels || [];
         const images = models.images || [];
         const sampleSize = models.sampleSize || 0;
        return Promise.all(
            labels.map(async label => {
                const descriptors = [];
                var url;
                for (let i = 1; i <= sampleSize; i++) {
                    url =  images.length > 0 ? images[i-1] : env.home + 'public/' + env.request.uri + `/recognition/${label}/${i}.png`;
                    const img = await faceapi.fetchImage(url);
                    const detections = await faceapi.detectSingleFace(img, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptor();
                    if (detections && detections.descriptor) {
                        descriptors.push(detections.descriptor);
                    };
                }
                return new faceapi.LabeledFaceDescriptors(label, descriptors);
            })
        );
    }
loadRecognition ( models = null ) { const labels = models . labels || [ ] ; const images = models . images || [ ] ; const sampleSize = models . sampleSize || 0 ; return Promise . all ( labels . map ( async label => { const descriptors = [ ] ; var url ; for ( let i = 1 ; i <= sampleSize ; i ++ ) { url = images . length > 0 ? images [ i - 1 ] : env . home + 'public/' + env . request . uri + ` ${ label } ${ i } ` ; const img = await faceapi . fetchImage ( url ) ; const detections = await faceapi . detectSingleFace ( img , new faceapi . TinyFaceDetectorOptions ( ) ) . withFaceLandmarks ( ) . withFaceDescriptor ( ) ; if ( detections && detections . descriptor ) { descriptors . push ( detections . descriptor ) ; } ; } return new faceapi . LabeledFaceDescriptors ( label , descriptors ) ; } ) ) ; }
Method that loads models for recognition
 @models: Object.
Method that loads models for recognition @models : Object .
// return a promise that loads all the images and fetches their descriptors // for each label get the descriptors based on the model image // iterate through all the model images in the folder (there are 6 right now and this number should be changed if more pics need to be added) // fetch the images from the model // detect the single face from the image // push the descriptiors from each image detection onto the decriptor collections that will be needed