Sunday 2 April 2017

Synchronous detection with opencv on node.js

I'm trying to implement face detection with opencv on web application. I currently send an image as base64 through socket.io from client-side to server and then detect face. But it seems like images that i send from the client is too fast. I also want to make it real-time as well. What i'm thinking is to detect a face with synchronous call.

   cv.readImage(buff, function(err, im){
    if (err) throw(err);
    if (im.width() < 1 || im.height() < 1) throw('Image has no size');
    faceDetection.detectMultiScale(im, function(err, faces){
      if (err) throw(err);
      if (faces.length > 0) {
        _.forEach(faces, function(face){
          im.rectangle([face.x, face.y], [face.width, face.height], rectColor, rectThickness);
          socket.emit('frame', { buffer: im.toBuffer() });
        });
      } else console.log("no face found");
    });

If I send a frame which doesn't contain any face back to the client as well, it's even more laggy. Shoot me some idea, I'm willing to try any solution. Thanks in advance :D



via thestrayed

No comments:

Post a Comment