From 3131e4aeb5f1a36da49223083576d26b0c372286 Mon Sep 17 00:00:00 2001 From: ihmc3jn09hk Date: Mon, 14 Oct 2019 10:40:23 +0800 Subject: [PATCH] Add webcam capture function for clients Using 'fswebcam' package. --- app.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index a78326c..c3a045d 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ -var version = '1.28'; +var version = '1.29'; var args = process.argv.slice(2); @@ -88,6 +88,16 @@ socket.on('take-photo', function(data){ takeImage(); }); +socket.on('take-photo-webcam', function(data){ + console.log("Taking a photo - WebCam"); + + photoStartTime = Date.now(); + lastReceiveTime = data.time + takeId = data.takeId; + + takeImage_WebCam(); +}); + socket.on('update-software', function(data){ console.log("Updating software"); @@ -125,8 +135,8 @@ function heartbeat() { socket.emit('camera-online', {name: cameraName, ipAddress: ipAddress, hostName: hostName, version: version, updateInProgress: updateInProgress}); } -function getAbsoluteImagePath() { - return path.join(__dirname, imagePath, imageName); +function getAbsoluteImagePath(prefix='') { + return path.join(__dirname, imagePath, prefix + imageName); } function lookupIp() { @@ -206,7 +216,7 @@ function takeImage() { //'-w', 2592, // width //'-h', 1944, // height //'-t', 100, // how long should taking the picture take? - '-q', 90, // quality + '-q', 95, // quality '-awb', 'fluorescent', '-o', getAbsoluteImagePath() // path + name ]; @@ -217,6 +227,23 @@ function takeImage() { imageProcess.on('exit', sendImage); } +function takeImage_WebCam() { + var args = [ + //'-w', 2592, // width + //'-h', 1944, // height + //'-t', 100, // how long should taking the picture take? + '-r', '1920x1080', // quality + '--no-banner', + getAbsoluteImagePath() // path + name + ]; + + var imageProcess = spawn('fswebcam', args); + // The image should take about 5 seconds, if its going after 10 kill it! + setTimeout(function(){ imageProcess.kill()}, 10000); + + imageProcess.on('exit', sendImage); +} + // To update the software we run git pull and npm install and then forcibily kill this process // Supervisor will then restart it function updateSoftware() {