Skip to content

Instantly share code, notes, and snippets.

@dataslayermedia
Created December 3, 2018 22:59
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dataslayermedia/29801e036b70c7bbbcfdbe77294f8329 to your computer and use it in GitHub Desktop.
Save dataslayermedia/29801e036b70c7bbbcfdbe77294f8329 to your computer and use it in GitHub Desktop.
ALPR License Plate Detection for Raspberry PI written in Node.js
const PiCamera = require('pi-camera');
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
setInterval(function() {
var path = './' + getRandomInt(500) + '.jpg';
const myCamera = new PiCamera({
mode: 'photo',
output: path,
width: 1920,
height: 1080,
nopreview: false,
});
myCamera.snap()
.then((result) => {
var exec = require('child_process').exec;
var cmd = 'alpr -c us -n 1 --json ' + path;
exec(cmd, function(error, stdout, stderr) {
var data = JSON.parse(stdout);
if (data.results.length > 0) {
console.log(data.results[0].plate);
} else {
console.log("\n\n\nNo license plate found.\n\n");
}
});
console.log(result);
})
.catch((error) => {
console.log(error);
});
}, 2e3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment