Last active
October 19, 2016 20:00
-
-
Save DroopyTersen/0f2a840b66cb1ff6e23c2b197fdcd0da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THIS IS A NODEJS WEB SERVER RUNNING ON PI | |
var bodyParser = require("body-parser"); | |
var express = require("express"); | |
var createGuid = require('node-uuid').v4; | |
var app = express(); | |
app.use(bodyParser.json()); //to handle POST body | |
// THESE DONT EXIST YET | |
var azureCam = require("azure-cam"); // bschlintz npm published module | |
var checkForFace = require("face-finder").checkForFace; //bschlintz npm published module. wrapper around openCV? | |
var getSkylineEmployee = require("./skyline-whoareyou") // thin wrapper module (not public) to promisify Fazio's cognitive services function | |
azureCam.setup("<azuresubscription>", "<blobcontainer>"); | |
// hookup middleware | |
azureCam.use(function(imgPath, next) { | |
checkForFace(imagePath).then(hasFace => { | |
if (hasFace) next(imgPath) | |
else throw new NoFaceException(); | |
}); | |
}) | |
app.post("/takepic", (req, res) => { | |
var deviceId = req.body.deviceId; | |
var trackingId = createGuid(); | |
azureCam.takePic(trackingId) | |
.then(blobId => { | |
return getSkylineEmployee(blobId, trackingId); | |
}) | |
.then(employee => { | |
res.send(employee); | |
}) | |
.catch(e => { | |
if (e instanceof NoFaceException) { | |
res.status(400).send(e); | |
} else { | |
res.status(500).send(e); | |
} | |
}) | |
}); | |
// Start the web server on the specified port | |
app.listen(3000, function() { | |
console.log("Server running on port 3000") | |
}); | |
function NoFaceException(msg) { | |
this.message = `Unable to find face in the image. ${msg}`.trim(); | |
this.name = "NoFaceException" | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not sure what exactly we'll need to pass around. but in this example, we create a 'trackingId' and use that to pass between all modules/microservices