-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster-cvcm.js
95 lines (85 loc) · 2.82 KB
/
cluster-cvcm.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var cluster = require('cluster');
var http = require('http');
var numCPUs = 100;//require('os').cpus().length;
var util = require('util');
var express = require('express');
var app = express();
function cv(FileName, cb, data) {
console.log(FileName);
var cv = require('openCV');
var easyimg = require('easyimage');
var Caman = require('caman').Caman;
cv.readImage("input/" + FileName, function(err, im){
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
var imgWidth = im.width();
console.log(err,faces);
Caman("input/" + FileName, function () {
this.resize({
width: 600
});
// this.crop(face.width*rate, face.height*rate ,face.x*rate , face.y*rate);
this.brightness(15)
this.exposure(15)
this.curves('rgb', [0, 0], [200, 0], [155, 255], [255, 255])
this.saturation(-50)
this.gamma(1.8)
this.vignette("50%", 60)
this.brightness(5)
this.contrast(30);
this.sepia(60);
this.render(function () {
// this.save('output/'+ FileName );
for (var i=0;i<faces.length; i++){
var face = faces[i]
var rate = 64/face.width;
im.ellipse(face.x + face.width/2, face.y + face.height/2, face.width/2, face.height/2);
Caman("input/" + FileName, function () {
this.resize({
width: imgWidth*rate
});
this.crop(face.width*rate, face.height*rate ,face.x*rate , face.y*rate);
this.brightness(15)
this.exposure(15)
this.curves('rgb', [0, 0], [200, 0], [155, 255], [255, 255])
this.saturation(-50)
this.gamma(1.8)
this.vignette("50%", 60)
this.brightness(5)
this.contrast(30);
this.sepia(60);
this.render(function () {
// this.save('output/crop/'+ FileName + '_' + i + '.jpg');
});
});
}
cb(JSON.stringify(faces));//
});
});
});
});
}
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log("worker("+worker.id+").exit " + worker.process.pid);
});
cluster.on('online', function(worker) {
console.log("worker("+worker.id+").online " + worker.process.pid);
});
cluster.on('listening', function(worker, address) {
console.log("worker("+worker.id+").listening " + address.address + ":" + address.port);
});
} else {
app.get('/:n', function(req, res) {
// var number=fib(req.params.n);
cv(req.params.n, function(str){
data = str.toString();
res.header('Access-Control-Allow-Origin','*');
res.write(''+data);
res.end();
});
});
app.listen(4000);
}