OPENCV with NodeJS

Posted By : Himanshu Goyal | 16-May-2016

Intro: OpenCV was introduce by intel corp,it provide the cpu intensive task and used in many application like:

  • 2D and 3D feature toolkits
  • Egomotion estimation
  • Facial recognition system
  • Gesture recognition
  • Human–computer interaction (HCI)
  • Mobile robotics
  • Motion understanding
  • Object identification
  • Segmentation and recognition
  • Stereopsis stereo vision: depth perception from 2 cameras
  • Structure from motion (SFM)
  • Motion tracking

OpenCV with NodeJS:  opencv in npm module which is used in nodejs to connect with opencv.The nodejs fully support opencv v2.4.5 to v2.4.11. The latest version v.3.0.0 is not yet fully supported and if you install the this version you may get the error in installing node module. 

  • npm install opencv //to install the node module 

Code for Counting faces and draw eclipse on faces of person:

var express = require('express');
var app = express();
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
var cv = require('opencv');
var fs = require('fs');

app.post('/upload', multipartMiddleware, function (req, res) {
    console.log("Control in the upload the image", req.files.file.path);
    var filePath = req.files.file.path;
    var fileExtension = req.files.file.name.split('.');
     cv.readImage(filePath, function (err, im) {
        console.log(err, "control in the cv", im);
        im.detectObject(cv.FACE_CASCADE, {}, function (err, faces) {
            console.log("Total number of faces", faces.length);
            for (var i = 0; i < faces.length; i++) {
                var x = faces[i];
                im.ellipse(x.x + x.width / 2, x.y + x.height / 2, x.width / 2, x.height / 2);
            }
            var storeFileName = new Date().getTime();
            var destinationPath = './images/' + storeFileName + "." + fileExtension[fileExtension.length - 1];
            im.save(destinationPath);
            res.send({
               object:"total number of faces : "+faces.length,
               message:"See the image with face eclipise on images folder"
            })
        });
    })
});



app.listen(4000, function () {
    console.log('Example app listening on port 4000!');
});
 

THANKS

 

 

About Author

Author Image
Himanshu Goyal

Himanshu is a bright Java ,Mean stack developer and have good knowledge of Hibernate, Spring,FFmepg,Neo4j JSON, Jquery, NODE.JS .His hobbies are learning new things, fitness .

Request for Proposal

Name is required

Comment is required

Sending message..