recognize(facedetector = this) {
         
         const detections = facedetector.app.detections || null;
         const options = facedetector.app.options || null;
         const canvas = facedetector.app.canvas || null;

        // Clear the canva so that it doesn't accumulate drawing at every detection
        canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
         
        // initialize the face matcher based on the recognition model loaded
        const labeledFaceDescriptors = options.recognitionModel;
        const faceMatcher = new faceapi.FaceMatcher(labeledFaceDescriptors, 0.6);

        const results = detections.map(d => faceMatcher.findBestMatch(d.descriptor));
        
        // expose the recognitions
        facedetector.app.recognitions = results;

        // For each detection, draw a box. Draw the match in a different color
        results.forEach((result, i) => {
            const box = detections[i].detection.box;

            // Let the box highlight matches in a different box colors
            const drawBox = new faceapi.draw.DrawBox(box, {
                label: result.toString(),
                boxColor: !result.toString().includes("unknown") ? 'rgba(255,0,0, 1)' : 'rgb(192,192,192,1)'
            });
            drawBox.draw(canvas);
        })

    }
/* 
     * Method that finds the best match for a face based on a model defined
     * 
     * @facedetector: FaceDetector object
     * - detections: face objects detected from the stream
     * - options: Optional. Object defining the different options applied to the rendering
     * - canvas: Optional. The canvas on which the drawings will be rendered
     *
     */
Method that finds the best match for a face based on a model defined

@facedetector: FaceDetector object
- detections: face objects detected from the stream
- options: Optional. Object defining the different options applied to the rendering
- canvas: Optional. The canvas on which the drawings will be rendered
Method that finds the best match for a face based on a model defined @facedetector : FaceDetector object - detections : face objects detected from the stream - options : Optional . Object defining the different options applied to the rendering - canvas : Optional . The canvas on which the drawings will be rendered
recognize(facedetector = this) {
         const detections = facedetector.app.detections || null;
         const options = facedetector.app.options || null;
         const canvas = facedetector.app.canvas || null;
        canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
        const labeledFaceDescriptors = options.recognitionModel;
        const faceMatcher = new faceapi.FaceMatcher(labeledFaceDescriptors, 0.6);
        const results = detections.map(d => faceMatcher.findBestMatch(d.descriptor));
        facedetector.app.recognitions = results;
        results.forEach((result, i) => {
            const box = detections[i].detection.box;
            const drawBox = new faceapi.draw.DrawBox(box, {
                label: result.toString(),
                boxColor: !result.toString().includes("unknown") ? 'rgba(255,0,0, 1)' : 'rgb(192,192,192,1)'
            });
            drawBox.draw(canvas);
        })
    }
recognize ( facedetector = this ) { const detections = facedetector . app . detections || null ; const options = facedetector . app . options || null ; const canvas = facedetector . app . canvas || null ; canvas . getContext ( '2d' ) . clearRect ( 0 , 0 , canvas . width , canvas . height ) ; const labeledFaceDescriptors = options . recognitionModel ; const faceMatcher = new faceapi . FaceMatcher ( labeledFaceDescriptors , 0.6 ) ; const results = detections . map ( d => faceMatcher . findBestMatch ( d . descriptor ) ) ; facedetector . app . recognitions = results ; results . forEach ( ( result , i ) => { const box = detections [ i ] . detection . box ; const drawBox = new faceapi . draw . DrawBox ( box , { label : result . toString ( ) , boxColor : ! result . toString ( ) . includes ( "unknown" ) ? 'rgba(255,0,0, 1)' : 'rgb(192,192,192,1)' } ) ; drawBox . draw ( canvas ) ; } ) }
Method that finds the best match for a face based on a model defined
Method that finds the best match for a face based on a model defined
// Clear the canva so that it doesn't accumulate drawing at every detection // initialize the face matcher based on the recognition model loaded // expose the recognitions // For each detection, draw a box. Draw the match in a different color // Let the box highlight matches in a different box colors