From a47b40444eaffcee8ce3ed0cb10c83b6d586789f Mon Sep 17 00:00:00 2001 From: Moe Date: Fri, 9 Apr 2021 14:10:31 -0700 Subject: [PATCH] Object Detect for 5 seconds instead of 1 frame when check Motion first --- libs/events/utils.js | 32 ++++++++++++++++++++++++-------- libs/monitor.js | 8 +++++--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libs/events/utils.js b/libs/events/utils.js index 67d511e2..6ba3a7d8 100644 --- a/libs/events/utils.js +++ b/libs/events/utils.js @@ -490,6 +490,29 @@ module.exports = (s,config,lang,app,io) => { extender(x,d) }) } + const sendFramesFromSecondaryOutput = (groupKey,monitorId,timeout) => { + const activeMonitor = s.group[groupKey].activeMonitors[monitorId] + const theEmitter = activeMonitor.secondaryDetectorOutput + if(!activeMonitor.sendingFromSecondaryDetectorOuput){ + s.debugLog('start sending object frames',groupKey,monitorId) + theEmitter.on('data',activeMonitor.secondaryDetectorOuputContentWriter = (data) => { + console.log(data) + s.ocvTx({ + f : 'frame', + mon : s.group[groupKey].rawMonitorConfigurations[monitorId].details, + ke : groupKey, + id : monitorId, + time : s.formattedTime(), + frame : data + }) + }) + } + clearTimeout(activeMonitor.sendingFromSecondaryDetectorOuput) + activeMonitor.sendingFromSecondaryDetectorOuput = setTimeout(() => { + theEmitter.removeListener('data',activeMonitor.secondaryDetectorOuputContentWriter) + delete(activeMonitor.sendingFromSecondaryDetectorOuput) + },timeout || 5000) + } const triggerEvent = async (d,forceSave) => { var didCountingAlready = false const filter = { @@ -559,14 +582,7 @@ module.exports = (s,config,lang,app,io) => { // if(d.doObjectDetection === true){ - s.ocvTx({ - f : 'frame', - mon : s.group[d.ke].rawMonitorConfigurations[d.id].details, - ke : d.ke, - id : d.id, - time : s.formattedTime(), - frame : s.group[d.ke].activeMonitors[d.id].lastJpegDetectorFrame - }) + sendFramesFromSecondaryOutput(d.ke,d.id) } // if( diff --git a/libs/monitor.js b/libs/monitor.js index f9d8edcd..96f0b4e9 100644 --- a/libs/monitor.js +++ b/libs/monitor.js @@ -58,6 +58,7 @@ module.exports = function(s,config,lang){ if(!activeMonitor.eventsCounted){activeMonitor.eventsCounted = {}}; if(!activeMonitor.isStarted){activeMonitor.isStarted = false}; if(!activeMonitor.pipe4BufferPieces){activeMonitor.pipe4BufferPieces = []}; + if(!activeMonitor.secondaryDetectorOutput){activeMonitor.secondaryDetectorOutput = new events.EventEmitter()}; if(activeMonitor.delete){clearTimeout(activeMonitor.delete)} if(!s.group[e.ke].rawMonitorConfigurations){s.group[e.ke].rawMonitorConfigurations={}} if(!activeMonitor.criticalErrors)activeMonitor.criticalErrors = { @@ -690,11 +691,12 @@ module.exports = function(s,config,lang){ } const onDetectorJpegOutputSecondary = (e,buffer) => { if(s.isAtleatOneDetectorPluginConnected){ - const theArray = s.group[e.ke].activeMonitors[e.id].pipe4BufferPieces + const activeMonitor = s.group[e.ke].activeMonitors[e.id] + const theArray = activeMonitor.pipe4BufferPieces theArray.push(buffer) if(buffer[buffer.length-2] === 0xFF && buffer[buffer.length-1] === 0xD9){ - s.group[e.ke].activeMonitors[e.id].lastJpegDetectorFrame = Buffer.concat(theArray) - s.group[e.ke].activeMonitors[e.id].pipe4BufferPieces = [] + activeMonitor.secondaryDetectorOutput.emit('data',Buffer.concat(theArray)) + activeMonitor.pipe4BufferPieces = [] } } }