Johannes Zellner 6 лет назад
Родитель
Сommit
7d2e9f8dcd
4 измененных файлов с 4 добавлено и 89 удалено
  1. 3 38
      index.js
  2. 0 41
      package-lock.json
  3. 1 2
      package.json
  4. 0 8
      public/index.html

+ 3 - 38
index.js

@@ -6,24 +6,7 @@ var express = require('express'),
     path = require('path'),
     fs = require('fs'),
     cors = require('cors'),
-    NodeWebcam = require('node-webcam');
-
-var opts = {
-    quality: 100,
-    saveShots: false,
-    output: 'jpeg',
-    device: false,
-    setValues: {
-        '"White Balance Temperature, Auto"': true
-    },
-    // device: '/dev/video2',
-    // [location, buffer, base64]
-    callbackReturn: 'location',
-    verbose: true
-};
-
-//Creates webcam instance
-var Webcam = NodeWebcam.create(opts);
+    execSync = require('child_process').execSync;
 
 const app = express();
 const port = process.env.PORT || 3000;
@@ -45,35 +28,17 @@ app.get('/pictures', function (req, res, next) {
     res.status(200).send({ pictures: entries.sort() });
 });
 
-app.get('/picture', function (req, res, next) {
-    var tmp = JSON.parse(JSON.stringify(opts));
-    tmp.callbackReturn = 'buffer';
-
-    console.log(req.query)
-
-    NodeWebcam.capture('/tmp/test', tmp, function (error, data) {
-        if (error) {
-            console.error(error);
-            return res.status(500).end();
-        }
-
-        res.status(200).send(data);
-    });
-});
-
 app.use(express.static('public'));
 
 function capture() {
     var filePath = path.join(picturePath, Date.now().toString());
     console.log('Taking picture', filePath);
 
-    NodeWebcam.capture(filePath, opts, function (error, data) {
-        if (error) console.error(error);
-    });
+    execSync(`fswebcam --jpeg 95 --save ${filePath}.jpeg --resolution 800x600 --frames 10`);
 }
 
 app.listen(port, function () {
     console.log(`Growcam listening on port ${port}`);
 
-    setInterval(capture, 30 * 1000);
+    setInterval(capture, 5 * 1000);
 });

+ 0 - 41
package-lock.json

@@ -4,11 +4,6 @@
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
-    "abbrev": {
-      "version": "1.1.1",
-      "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
-      "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
-    },
     "accepts": {
       "version": "1.3.7",
       "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
@@ -249,23 +244,6 @@
       "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
       "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
     },
-    "node-webcam": {
-      "version": "0.6.0",
-      "resolved": "https://registry.npmjs.org/node-webcam/-/node-webcam-0.6.0.tgz",
-      "integrity": "sha512-W19B8Mpejzn+ZH+kXDH6YFX9ZrTmNqaCwfr7Yfhqxgx7ze7BFEEFFaxqaaNnPhUKEkjtA0UProXrly5G5eKMTQ==",
-      "requires": {
-        "nopt": "*"
-      }
-    },
-    "nopt": {
-      "version": "4.0.3",
-      "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz",
-      "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
-      "requires": {
-        "abbrev": "1",
-        "osenv": "^0.1.4"
-      }
-    },
     "object-assign": {
       "version": "4.1.1",
       "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@@ -279,25 +257,6 @@
         "ee-first": "1.1.1"
       }
     },
-    "os-homedir": {
-      "version": "1.0.2",
-      "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
-      "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M="
-    },
-    "os-tmpdir": {
-      "version": "1.0.2",
-      "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
-      "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
-    },
-    "osenv": {
-      "version": "0.1.5",
-      "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz",
-      "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==",
-      "requires": {
-        "os-homedir": "^1.0.0",
-        "os-tmpdir": "^1.0.0"
-      }
-    },
     "parseurl": {
       "version": "1.3.3",
       "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",

+ 1 - 2
package.json

@@ -10,7 +10,6 @@
   "license": "ISC",
   "dependencies": {
     "cors": "^2.8.5",
-    "express": "^4.17.1",
-    "node-webcam": "^0.6.0"
+    "express": "^4.17.1"
   }
 }

+ 0 - 8
public/index.html

@@ -20,10 +20,6 @@ function reload() {
     document.getElementById('currentPictureLabel').innerText = pictures[i++];
 }
 
-function takePicture() {
-    document.getElementById('picture').src = origin + '/picture?' + Date.now();
-}
-
 function getPictureList() {
     var req = new XMLHttpRequest();
     req.addEventListener('load', function () {
@@ -59,9 +55,5 @@ window.onload = function () {
     <p>Pictures available: <span id="pictureCount"></span> showing <span id="currentPictureLabel"></span></p>
     <img id="stream" width="800" onclick="pausePlay()"/>
 
-    <br/>
-
-    <img id="picture" width="400" height="400" onclick="takePicture()"/>
-
 </body>
 </html>