Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to compare detected face with image

using opens.js able to detect the face from video source but how to identify image from array of blobs

    let width = vidIn.videoWidth;cvsOut.width = vidIn.width = width;
    let height = vidIn.videoHeight;cvsOut.height = vidIn.height = height;
    let cap = new cv.VideoCapture(vidIn);
    let src = new cv.Mat(height,width,cv.CV_8UC4);
    let dst = new cv.Mat(height,width,cv.CV_8UC4);
    let gray = new cv.Mat();
    let classifier = new cv.CascadeClassifier();
    let fps = 24;
    let faces = new cv.RectVector();
    let msize = new cv.Size(0,0);
    const utils = new Utils('error message');
    let faceCascadeFile = 'haarcascade_frontalface_default.xml';
    utils.createFileFromUrl(faceCascadeFile,faceCascadeFile,()=>{
        console.log('cascade loaded');
        classifier.load(faceCascadeFile);
        let begin = Date.now();
        function processVideo(){
            cap.read(src);
            src.copyTo(dst);
            cv.cvtColor(dst, gray, cv.COLOR_RGBA2GRAY, 0);
            //detect face
            try{
                classifier.detectMultiScale(gray, faces, 1.1, 3, 0,msize,msize);
                console.dir(faceCascadeFile,faces.size());
            }catch(err){
                console.error('detectMultiScale error: ',err);
            }

            // draw face
            for (let i = 0; i < faces.size(); ++i) {
                let face = faces.get(i);
                let point1 = new cv.Point(face.x, face.y);
                let point2 = new cv.Point(face.x + face.width, face.y + face.height);
                cv.rectangle(dst, point1, point2, [255, 0, 0, 255]);
            }
            // output to canvas
            cv.imshow(cvsOut,dst);
            let delay = 1000/fps -(Date.now()-begin);
            setTimeout(processVideo,delay);
        }
        setTimeout(processVideo,0);
    });