Commit 7f545879 authored by Michael Murtaugh's avatar Michael Murtaugh

server with node-static

parent 247bf755
@font-face {
font-family: "Logisoso";
src: url("fonts/Logisoso.ttf");
}
body {
font-family: "Logisoso", serif;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SICV: camera</title>
<link rel="stylesheet" href="client.css">
<script src="lib/d3.min.js"></script>
<script src="lib/socket.io.js"></script>
<script src="lib/collagecode.js"></script>
<script src="client.js"></script>
</head>
<body></body>
</html>
document.addEventListener("DOMContentLoaded", function () {
var FONT = "Logisoso",
STATIC_BASE = "";
/* CAMERA */
function imageloop (redraw) {
......@@ -122,28 +123,30 @@ document.addEventListener("DOMContentLoaded", function () {
});
socket.on("facedetect", function (data) {
// console.log("facedetect", data);
faces.push(data);
var i = loop.next();
if (i == 0) {
faces.push(data[0]);
var i = loop.next(); // now showing the analyzed frame
if (i == 29) {
console.log("end of analysis, faces:", faces.length);
state = STATE_SHOW_ANALYSIS;
loop.run();
image2screen = cc.transform_from(
cc.rect(0, 0, loop.images(0).width, loop.images(0).height),
cc.rect(0, 0, canvas.width, canvas.height)
)
} else {
window.setTimeout(analyzeframe, 0);
}
})
function analyzeframe () {
socket.emit("facedetect", { path: urltopath(loop.current_image().src) });
var i = loop.index(),
next_image = loop.images(i+1);
// console.log("analyzeframe", i+1, urltopath(next_image.src));
socket.emit("facedetect", { paths: [ urltopath(next_image.src) ] });
}
var stripurlpat = new RegExp("^https?://.+?/(.*)$");
function urltopath (url) {
if (url.indexOf(STATIC_BASE) == 0) {
return url.substring(STATIC_BASE.length);
var m = stripurlpat.exec(url);
if (m !== null) {
console.log("urltopath", m)
return m[1];
}
return url;
}
......@@ -176,8 +179,8 @@ document.addEventListener("DOMContentLoaded", function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (state == STATE_COUNTDOWN) {
ctx.font = "200px serif";
var msg = ""+countdown_time;
ctx.font = "200px "+FONT;
var msg = "Log "+countdown_time;
var text = ctx.measureText(msg);
ctx.fillStyle = "red";
ctx.fillRect(0, 0, canvas.width, canvas.height);
......@@ -187,7 +190,7 @@ document.addEventListener("DOMContentLoaded", function () {
} else if (state == STATE_RECORDING) {
loop.draw(ctx);
var fs = 50;
ctx.font = fs+"px serif";
ctx.font = fs+"px "+FONT;
var msg = "RECORDING";
var text = ctx.measureText(msg);
ctx.textBaseline = "hanging";
......@@ -195,7 +198,11 @@ document.addEventListener("DOMContentLoaded", function () {
ctx.fillText(msg, (canvas.width-text.width)/2, (canvas.height-fs)/2);
if (loop.index() == 29) {
loop.index(0);
image2screen = cc.transform_from(
cc.rect(0, 0, loop.images(0).width, loop.images(0).height),
cc.rect(0, 0, canvas.width, canvas.height)
)
loop.index(-1);
console.log("starting analysis", loop.images().length + " images");
state = STATE_ANALYZING;
window.setTimeout(analyzeframe, 1000);
......@@ -204,12 +211,31 @@ document.addEventListener("DOMContentLoaded", function () {
} else if (state == STATE_ANALYZING) {
loop.draw(ctx);
var fs = 50;
ctx.font = fs+"px serif";
var msg = "ANALYZING";
ctx.font = fs+"px "+FONT;
var msg = "haarcascade_frontalface_default";
var text = ctx.measureText(msg);
ctx.textBaseline = "hanging";
ctx.fillStyle = "red";
ctx.fillText(msg, (canvas.width-text.width)/2, (canvas.height-fs)/2);
var i = loop.index(),
f = faces[i];
// draw FACES
if (f && f.faces) {
ctx.strokeStyle = "blue";
ctx.lineWidth = 3;
f.faces.forEach(function (x) {
var r = image2screen(cc.rect(x[0], x[1], x[2], x[3]));
ctx.strokeRect(r.x, r.y, r.width, r.height);
// console.log("draw", x);
});
ctx.strokeStyle = "green";
f.eyes.forEach(function (x) {
var r = image2screen(cc.rect(x[0], x[1], x[2], x[3]));
ctx.strokeRect(r.x, r.y, r.width, r.height);
})
}
} else if (state == STATE_SHOW_ANALYSIS) {
loop.draw(ctx);
var i = loop.index(),
......@@ -256,7 +282,8 @@ document.addEventListener("DOMContentLoaded", function () {
STATE_RECORDING = -2,
STATE_ANALYZING = -3,
STATE_SHOW_ANALYSIS = -4,
state = 0;
STATE_SELECT_FRAME = -5,
state = STATE_COUNTDOWN;
var countdown_time = 3;
......@@ -266,19 +293,10 @@ document.addEventListener("DOMContentLoaded", function () {
}
function countdown () {
ctx.font = "200px serif";
var msg = ""+countdown_time;
var text = ctx.measureText(msg);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "red";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.textBaseline = "hanging";
ctx.fillStyle = "black";
ctx.fillText(msg, (canvas.width-text.width)/2, (canvas.height-100)/2);
countdown_time--;
window.requestAnimationFrame(draw);
if (countdown_time > 0) {
window.setTimeout(countdown, 1000);
} else {
state = STATE_RECORDING;
console.log("RECORD");
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -3,7 +3,14 @@
var fs = require("fs"),
app = require('http').createServer(handler),
io = require('socket.io').listen(app),
spawn = require("child_process").spawn;
spawn = require("child_process").spawn,
nstatic = require('node-static'),
util = require('util');
var staticfiles = new(nstatic.Server)(".", {
cache: 600,
headers: { 'X-Powered-By': 'node-static' }
});
// load the settings
var settings = JSON.parse(fs.readFileSync("settings.json", "utf8"));
......@@ -13,7 +20,7 @@ var STATIC_ROOT = "http://" + settings.ipaddress,
TITLE = "SICV",
PAGE = '<!doctype html>\n<html lang="en"><head><meta charset="utf-8">';
PAGE += '<title>'+TITLE+'</title>\n';
PAGE += '<link rel="stylesheet" href="'+STATIC_ROOT+'/poc/16/sicvitrine/client.css">\n';
PAGE += '<link rel="stylesheet" href="'+STATIC_ROOT+'/poc/16/vitrine/client.css">\n';
PAGE += '<script src="'+STATIC_ROOT+'/lib/d3.min.js"></script>\n';
PAGE += '<script src="'+STATIC_ROOT+'/poc/16/sicvitrine/socket.io.js"></script>\n';
PAGE += '<script src="'+STATIC_ROOT+'/lib/collagecode.js"></script>\n';
......@@ -26,8 +33,25 @@ console.log("Starting server, listening on " + settings.ipaddress + ":" + settin
app.listen(settings.port);
function handler (req, res) {
res.writeHead(200);
res.end(PAGE);
// res.writeHead(200);
// res.end(PAGE);
// console.log("req", req, res);
console.log("REQEND")
staticfiles.serve(req, res, function(err, result) {
if (err) {
console.error('Error serving %s - %s', req.url, err.message);
if (err.status === 404 || err.status === 500) {
staticfiles.serveFile(util.format('/%d.html', err.status), err.status, {}, req, res);
} else {
res.writeHead(err.status, err.headers);
res.end();
}
} else {
console.log('%s - %s', req.url, res.message);
}
});
}
io.sockets.on('connection', function (socket) {
......@@ -55,8 +79,8 @@ io.sockets.on('connection', function (socket) {
})
socket.on("facedetect", function (data) {
console.log("facedetect", data.path);
var faces = spawn("./getfaces.py", [data.path]);
console.log("facedetect", data.paths);
var faces = spawn("./getfaces.py", data.paths);
faces.stdout.setEncoding("utf8");
faces.stdout.on("data", function (text) {
var data = JSON.parse(text);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment