opencv plugin no longer using cascades folder

- opencv4nodejs provides compatible cascades and those are the only ones provided and usable now.
- put face-recognition plugin back to 0.9.3 for compatibility
- fix syntax for extender
merge-requests/36/head
Moe 2018-11-03 19:16:54 -07:00
parent fef3ca8eb7
commit ca3619c1a8
3 changed files with 17 additions and 27 deletions

View File

@ -8,7 +8,7 @@
"express": "^4.16.2",
"moment": "^2.19.2",
"socket.io": "^2.0.4",
"face-recognition-cuda": "^0.9.3a"
"face-recognition-cuda": "0.9.3"
},
"devDependencies": {},
"scripts": {

View File

@ -24,29 +24,22 @@ try{
}
// Base Init />>
// OpenCV Init >>
var exec = require('child_process').exec;
var cv = require('opencv4nodejs');
if(config.cascadesDir===undefined){config.cascadesDir=__dirname+'/cascades/'}
if(config.alprConfig===undefined){config.alprConfig=__dirname+'/openalpr.conf'}
s.foundCascades = {}
s.dir.cascades = config.cascadesDir
//streams dir
if(!fs.existsSync(s.dir.cascades)){
fs.mkdirSync(s.dir.cascades);
}
s.findCascades = function(callback){
var tmp={};
tmp.foundCascades=[];
fs.readdir(s.dir.cascades,function(err,files){
files.forEach(function(cascade,n){
if(cascade.indexOf('.xml')>-1){
tmp.foundCascades.push(cascade.replace('.xml',''))
}
})
s.cascadesInDir=tmp.foundCascades;
callback(tmp.foundCascades)
var foundCascades = []
Object.keys(cv).forEach(function(cascade,n){
if(cascade.indexOf('HAAR_') >- 1){
foundCascades.push(cascade)
}
})
s.cascadesInDir = foundCascades
s.systemLog('Found '+foundCascades.length+' Cascades')
callback(foundCascades)
}
s.findCascades(function(){
s.findCascades(function(cascades){
//get cascades
})
s.onPluginEventExtender(function(d,cn,tx){
@ -76,13 +69,10 @@ s.detectObject = function(buffer,d,tx,frameLocation){
return
}
selectedCascades.forEach(function(cascade){
var cascadePath = s.dir.cascades+cascade+'.xml'
if(s.foundCascades[cascadePath] === undefined){
s.foundCascades[cascadePath] = fs.existsSync(cascadePath)
}else if(s.foundCascades[cascadePath] === false){
return s.systemLog('Attempted to use non existant cascade. : '+cascadePath)
if(!cv[cascade]){
return s.systemLog('Attempted to use non existant cascade. : '+cascade)
}
var classifier = new cv.CascadeClassifier(cascadePath)
var classifier = new cv.CascadeClassifier(cv[cascade])
var matrices = classifier.detectMultiScaleGpu(im).objects
if(matrices.length > 0){
matrices.forEach(function(v,n){

View File

@ -158,10 +158,10 @@ module.exports = function(__dirname,config){
}
}
break;
s.onPluginEvent.forEach(function(extender){
extender(d,cn,tx)
})
}
s.onPluginEvent.forEach(function(extender){
extender(d,cn,tx)
})
}
server = http.createServer(app).on('error', function(err){
if(err.code === 'EADDRINUSE'){