-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencv.js
66 lines (56 loc) · 1.56 KB
/
opencv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Cloudspokes challenge #1840
*
* Main class of the OpenCV port
* Exposes very few methods, as the work is done by the "detector" class.
*
* @author [email protected]
* @version
*/
var fs = require('fs'),
path = require('path'),
// compiled c++ library exposed with BEA to the v8 engine
cv = require('opencv-node'),
// module of object detection (faces && eyes)
Detector = require('./detector'),
// for socket communication
pusher = require('./pusher.js');
/**
* Meet the Matrix class.
* the basis for all the calculus in opencv.
*/
var Mat = cv.Mat;
// the image object used in the application (mockup || user-uploaded)
var inputImage = {
url: null,
mat: null
};
/**
* Main
*
* Wraps up the detector class.
*
* @param{string} the url of the image to process
*/
function init( data ){
var src = data.src,
channel = data.channel;
pusher.trigger( channel, 'opencv-info', {msg:'Reading image from disk'});
// read image into opencv Matrix format
inputImage.src = src;
inputImage.mat = cv.imread(inputImage.src, 1);
pusher.trigger( channel, 'opencv-info', {msg:'Image finished loading'});
// instantiate the detector submodule
var detector = new Detector();
// detect regions of interest (eyes for now)
var roi = detector.getROI(inputImage.mat);
process.send({roi:roi});
// use the previously calculated ROIs to get iris center and radius
var iris = detector.getIris();
process.send({ iris:iris });
};
// Message from parent process starts calculus
process.on('message', function(msg) {
console.log("opencv recieved: " + msg);
init(msg);
});