Last active
July 21, 2018 03:16
-
-
Save marce1994/3a7f3ffb401433cdc8aaf64e6298110d to your computer and use it in GitHub Desktop.
something went wrong
This file contains hidden or 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
const { StreamCamera, Codec } = require("pi-camera-connect"); | |
const fs = require("fs"); | |
const cv = require('opencv4nodejs'); | |
var locks = require('locks'); | |
var mutex = locks.createMutex(); | |
const streamCamera = new StreamCamera({ | |
codec: Codec.H264, | |
fps: 10, | |
width: 1920, | |
height: 1080 | |
}); | |
const videoStream = streamCamera.createStream(); | |
videoStream.on("start", function(data){ | |
console.log("Video stream has started"); | |
}); | |
videoStream.on("error", function(error){ | |
console.log(error); | |
}); | |
videoStream.on("data",function(data){ | |
console.log(mutex.isLocked); | |
try{ | |
if(!mutex.isLocked){ | |
mutex.lock(async function(){ | |
const classifier = new cv.CascadeClassifier(cv.HAAR_FRONTALFACE_ALT2); | |
const matFromArray = new cv.Mat(Buffer.from(data), 1920, 1080, cv.CV_8UC3); | |
const grayImg = matFromArray.bgrToGray(); | |
console.log("procesando imagen"); | |
const { objects, numDetections } = await classifier.detectMultiScaleAsync(grayImg); | |
mutex.unlock(); | |
}); | |
} | |
}catch(err){ | |
console.log(err); | |
if(mutex.isLocked){ | |
mutex.unlock(); | |
} | |
} | |
}); | |
videoStream.on("end", function(data){ | |
console.log("Video stream has ended"); | |
}); | |
const runApp = async () => { | |
await streamCamera.startCapture(); | |
while(true){ | |
try{ | |
name = (Date.now() / 1000 | 0) + ".h264"; | |
console.log("Nuevo archivo ("+name+")"); | |
const writeStream = fs.createWriteStream(name); | |
// Pipe the video stream to our video file | |
videoStream.pipe(writeStream); | |
writeStream.on("finish",function(){ | |
console.log("Archivo grabado"); | |
}); | |
writeStream.on("error",function(err){ | |
console.log(err); | |
}); | |
// Wait for 5 seconds | |
await new Promise(resolve => setTimeout(() => resolve(), 100000)); | |
writeStream.close(); | |
}catch(err){ | |
console.log(err); | |
} | |
} | |
}; | |
runApp(); |
This file contains hidden or 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
FROM resin/raspberrypi3-buildpack-deps:jessie | |
ENV NODE_VERSION 10.0.0 | |
RUN curl -SLO "http://resin-packages.s3.amazonaws.com/node/v$NODE_VERSION/node-v$NODE_VERSION-linux-armv7hf.tar.gz" \ | |
&& tar -xzf "node-v$NODE_VERSION-linux-armv7hf.tar.gz" -C /usr/local --strip-components=1 \ | |
&& rm "node-v$NODE_VERSION-linux-armv7hf.tar.gz" \ | |
&& npm config set unsafe-perm true -g --unsafe-perm \ | |
&& rm -rf /tmp/* | |
RUN apt-get update && apt-get upgrade -y | |
RUN apt-get install -y build-essential \ | |
cmake \ | |
pkg-config \ | |
python3-dev \ | |
python3-numpy \ | |
python3-pip \ | |
libopenblas-dev | |
RUN apt-get install libraspberrypi-dev raspberrypi-kernel-headers -y | |
RUN usermod -a -G video root | |
RUN npm i face-recognition | |
RUN npm i raspberry-pi-camera-native --unsafe-perm | |
RUN npm i jpeg-js node-raspistill | |
RUN npm i opencv4nodejs | |
RUN npm i locks | |
RUN npm i pi-camera-connect | |
COPY main.js main.js | |
ENTRYPOINT [ "node", "main.js" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sergio Daniel Xalambrí [18:17]
no es buena idea eso, podés estar causando que la app corra muchas veces y se llene la memoria
mejor hace esto: