forked from peterbraden/node-opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
face-proxy.js
executable file
·46 lines (34 loc) · 1.18 KB
/
face-proxy.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
/*
Face recognition proxy
*/
var http = require('http')
, request = require('request')
, cv = require('../lib/opencv')
, face_cascade = new cv.CascadeClassifier("./data/haarcascade_frontalface_alt.xml")
http.createServer(function(req, resp){
var url = req.url.slice(1);
console.log(url);
if (url.indexOf('http') != 0){
return request({uri:'http://google.com'}).pipe(resp)
}
// TODO make sure image
if (url.indexOf(".jpg", url.length - 4) !== -1 ||
url.indexOf(".png", url.length - 4) !== -1){
request({uri:url, encoding:'binary'}, function(err, r, body){
if (err) throw err;
cv.readImage(new Buffer(body, 'binary'), function(err, im){
im.faceDetect(im, {}, function(err, faces){
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);
}
//console.log(faces);
resp.writeHead(200, {'Content-Type': 'image/jpeg'});
resp.end(im.toBuffer());
});
});
})
} else {
request({uri:url || 'http://google.com'}).pipe(resp)
}
}).listen(1901)