Update OpenALPR Plugin to use C++ base
- This will make it so the classifier is not loaded for every frame. It is loaded once and then frames are run against it while the plugin daemon is active.pushover
parent
791a281f88
commit
48444b4ddf
|
|
@ -33,7 +33,10 @@ else
|
|||
fi
|
||||
echo "-----------------------------------"
|
||||
echo "Installing Modules.."
|
||||
npm install --unsafe-perm
|
||||
apt install node-pre-gyp -y
|
||||
npm install nopt npmlog rimraf semver -g
|
||||
npm install
|
||||
npm uninstall nopt npmlog rimraf semver -g
|
||||
echo "Finding and Fixing Module Vulnerabilities.."
|
||||
npm audit fix --force
|
||||
echo "Shinobi - Do you want to start the plugin?"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
"dependencies": {
|
||||
"express": "^4.16.2",
|
||||
"moment": "^2.19.2",
|
||||
"socket.io": "^2.0.4"
|
||||
"socket.io": "^2.0.4",
|
||||
"node-openalpr-shinobi": "1.1.4"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@
|
|||
var fs = require('fs');
|
||||
var config = require('./conf.json')
|
||||
var exec = require('child_process').exec;
|
||||
var openalpr = {
|
||||
us: require ("node-openalpr-shinobi"),
|
||||
eu: require ("node-openalpr-shinobi"),
|
||||
};
|
||||
var s
|
||||
try{
|
||||
s = require('../pluginBase.js')(__dirname,config)
|
||||
|
|
@ -29,100 +33,61 @@ try{
|
|||
if(config.alprConfig === undefined){
|
||||
config.alprConfig = __dirname + '/openalpr.conf'
|
||||
}
|
||||
// OpenALPR Init />>
|
||||
s.detectObject = function(buffer,d,tx,frameLocation){
|
||||
var detectStuff = function(frame){
|
||||
try{
|
||||
exec('alpr -j --config '+config.alprConfig+' -c '+d.mon.detector_lisence_plate_country+' '+frame,{encoding:'utf8'},(err, scan, stderr) => {
|
||||
if(err){
|
||||
s.systemLog(err);
|
||||
}else{
|
||||
try{
|
||||
try{
|
||||
if(scan.indexOf('Initialize OpenCL runtime...') > -1){
|
||||
scan = scan.split('Initialize OpenCL runtime...')[1].trim()
|
||||
}
|
||||
scan = JSON.parse(scan.replace('--(!)Loaded CUDA classifier','').trim())
|
||||
}catch(err){
|
||||
if(!scan||!scan.results){
|
||||
return s.systemLog(scan,err);
|
||||
}
|
||||
}
|
||||
// console.log('scan',scan)
|
||||
if(scan.results.length > 0){
|
||||
scan.plates=[]
|
||||
scan.mats=[]
|
||||
scan.results.forEach(function(v){
|
||||
v.candidates.forEach(function(g,n){
|
||||
if(v.candidates[n].matches_template){
|
||||
delete(v.candidates[n].matches_template)
|
||||
}
|
||||
})
|
||||
scan.plates.push({
|
||||
coordinates: v.coordinates,
|
||||
candidates: v.candidates,
|
||||
confidence: v.confidence,
|
||||
plate: v.plate
|
||||
})
|
||||
var width = Math.sqrt( Math.pow(v.coordinates[1].x - v.coordinates[0].x, 2) + Math.pow(v.coordinates[1].y - v.coordinates[0].y, 2));
|
||||
var height = Math.sqrt( Math.pow(v.coordinates[2].x - v.coordinates[1].x, 2) + Math.pow(v.coordinates[2].y - v.coordinates[1].y, 2))
|
||||
scan.mats.push({
|
||||
x: v.coordinates[0].x,
|
||||
y: v.coordinates[0].y,
|
||||
width: width,
|
||||
height: height,
|
||||
tag: v.plate
|
||||
})
|
||||
})
|
||||
tx({
|
||||
f: 'trigger',
|
||||
id: d.id,
|
||||
ke: d.ke,
|
||||
details: {
|
||||
plug: config.plug,
|
||||
name: 'licensePlate',
|
||||
reason: 'object',
|
||||
matrices: scan.mats,
|
||||
imgHeight: d.mon.detector_scale_y,
|
||||
imgWidth: d.mon.detector_scale_x,
|
||||
frame: d.base64
|
||||
}
|
||||
})
|
||||
}
|
||||
}catch(err){
|
||||
s.systemLog(scan,err);
|
||||
}
|
||||
}
|
||||
fs.unlink(frame,function(){
|
||||
|
||||
})
|
||||
})
|
||||
}catch(err){
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
if(frameLocation){
|
||||
detectStuff(frameLocation)
|
||||
}else{
|
||||
d.tmpFile=s.gid(5)+'.jpg'
|
||||
if(!fs.existsSync(s.dir.streams)){
|
||||
fs.mkdirSync(s.dir.streams);
|
||||
}
|
||||
d.dir=s.dir.streams+d.ke+'/'
|
||||
if(!fs.existsSync(d.dir)){
|
||||
fs.mkdirSync(d.dir);
|
||||
}
|
||||
d.dir=s.dir.streams+d.ke+'/'+d.id+'/'
|
||||
if(!fs.existsSync(d.dir)){
|
||||
fs.mkdirSync(d.dir);
|
||||
}
|
||||
fs.writeFile(d.dir+d.tmpFile,buffer,function(err){
|
||||
if(err) return s.systemLog(err);
|
||||
try{
|
||||
detectStuff(d.dir+d.tmpFile)
|
||||
}catch(error){
|
||||
console.error('Catch: ' + error);
|
||||
Object.keys(openalpr).forEach(function(region){
|
||||
openalpr[region].Start(config.alprConfig, null, null, true, region)
|
||||
})
|
||||
var convertResultsToMatrices = function(results){
|
||||
var mats = []
|
||||
var plates = []
|
||||
results.forEach(function(v){
|
||||
v.candidates.forEach(function(g,n){
|
||||
if(v.candidates[n].matches_template){
|
||||
delete(v.candidates[n].matches_template)
|
||||
}
|
||||
})
|
||||
plates.push({
|
||||
coordinates: v.coordinates,
|
||||
candidates: v.candidates,
|
||||
confidence: v.confidence,
|
||||
plate: v.plate
|
||||
})
|
||||
var width = Math.sqrt( Math.pow(v.coordinates[1].x - v.coordinates[0].x, 2) + Math.pow(v.coordinates[1].y - v.coordinates[0].y, 2));
|
||||
var height = Math.sqrt( Math.pow(v.coordinates[2].x - v.coordinates[1].x, 2) + Math.pow(v.coordinates[2].y - v.coordinates[1].y, 2))
|
||||
mats.push({
|
||||
x: v.coordinates[0].x,
|
||||
y: v.coordinates[0].y,
|
||||
width: width,
|
||||
height: height,
|
||||
tag: v.plate
|
||||
})
|
||||
})
|
||||
return mats
|
||||
}
|
||||
// OpenALPR Init />>
|
||||
s.detectObject = function(buffer,d,tx,frameLocation){
|
||||
try{
|
||||
var region = d.mon.detector_lisence_plate_country || 'us'
|
||||
openalpr[region].IdentifyLicense(buffer, {}, function (error, output){
|
||||
var results = output.results
|
||||
if(results.length > 0){
|
||||
var matrices = convertResultsToMatrices(results)
|
||||
tx({
|
||||
f: 'trigger',
|
||||
id: d.id,
|
||||
ke: d.ke,
|
||||
details: {
|
||||
plug: config.plug,
|
||||
name: 'licensePlate',
|
||||
reason: 'object',
|
||||
matrices: matrices,
|
||||
imgHeight: d.mon.detector_scale_y,
|
||||
imgWidth: d.mon.detector_scale_x,
|
||||
frame: d.base64
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}catch(err){
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue