2018-06-09 23:34:06 +00:00
//
// Shinobi - OpenALPR Plugin
// Copyright (C) 2016-2025 Moe Alam, moeiscool
//
// # Donate
//
// If you like what I am doing here and want me to continue please consider donating :)
// PayPal : paypal@m03.ca
//
2018-11-03 06:38:23 +00:00
// Base Init >>
var fs = require ( 'fs' ) ;
var config = require ( './conf.json' )
2018-06-09 23:34:06 +00:00
var exec = require ( 'child_process' ) . exec ;
2019-08-07 01:53:35 +00:00
var openalpr = {
us : require ( "node-openalpr-shinobi" ) ,
eu : require ( "node-openalpr-shinobi" ) ,
} ;
2018-11-03 06:38:23 +00:00
var s
try {
s = require ( '../pluginBase.js' ) ( _ _dirname , config )
} catch ( err ) {
console . log ( err )
try {
s = require ( './pluginBase.js' ) ( _ _dirname , config )
} catch ( err ) {
console . log ( err )
return console . log ( config . plug , 'Plugin start has failed. This may be because you started this plugin on another machine. Just copy the pluginBase.js file into this (plugin) directory.' )
return console . log ( config . plug , 'pluginBase.js was not found.' )
2018-06-09 23:34:06 +00:00
}
}
2018-11-03 06:38:23 +00:00
// Base Init />>
// OpenALPR Init >>
2019-01-08 23:27:28 +00:00
if ( config . alprConfig === undefined ) {
config . alprConfig = _ _dirname + '/openalpr.conf'
}
2019-08-07 01:53:35 +00:00
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
}
2018-11-03 06:38:23 +00:00
// OpenALPR Init />>
s . detectObject = function ( buffer , d , tx , frameLocation ) {
2019-08-07 01:53:35 +00:00
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
2018-06-09 23:34:06 +00:00
}
2018-11-03 06:38:23 +00:00
} )
}
2018-06-09 23:34:06 +00:00
} )
2019-08-07 01:53:35 +00:00
} catch ( err ) {
console . log ( err )
2018-11-03 06:38:23 +00:00
}
}