diff --git a/languages/en_CA.json b/languages/en_CA.json index 1ecad4f1..6f64f283 100644 --- a/languages/en_CA.json +++ b/languages/en_CA.json @@ -972,6 +972,7 @@ "Automatic":"Automatic", "Max Latency":"Max Latency", "Loop Stream":"Loop Stream", + "Object Count":"Object Count", "Object Tag":"Object Tag", "Noise Filter":"Noise Filter", "Noise Filter Range":"Noise Filter Range", @@ -981,6 +982,8 @@ "TV Channel Group":"TV Channel Group", "Emotion Average":"Emotion Average", "Require Object to be in Region":"Require Object to be in Region", + "Numeric criteria unsupported for Region tests, Ignoring Conditional":"Numeric criteria unsupported for Region tests, Ignoring Conditional", + "Text criteria unsupported for Object Count tests, Ignoring Conditional":"Text criteria unsupported for Object Count tests, Ignoring Conditional", "Show Regions of Interest":"Show Regions of Interest", "Confidence of Detection":"Confidence of Detection", "Edit Selected":"Edit Selected", diff --git a/libs/events.js b/libs/events.js index ef03021d..645f9987 100644 --- a/libs/events.js +++ b/libs/events.js @@ -218,10 +218,21 @@ module.exports = function(s,config,lang){ } return newVal } + var compressMatrices = function(passedMatrices){ + // remove empty elements + passedMatrices = passedMatrices.filter(value => Object.keys(value).length !== 0) + // remove duplicate matches + passedMatrices = passedMatrices.filter((matrix, index, self) => + index === self.findIndex((t) => ( + t.x === matrix.x && t.y === matrix.y && t.tag === matrix.tag && t.confidence === matrix.confidence + )) + ) + return(passedMatrices) + } var defaultDrop = true; // forces unmatched events to be dropped var testMatrices = [...allMatrices] // default var filters = currentConfig.detector_filters - var hasFilters = (filters.length > 0) + var hasFilters = (Object.keys(filters).length > 0) Object.keys(filters).forEach(function(key){ var conditionChain = {} testMatrices = [...allMatrices] // for new filter reset the matrices to be tested against @@ -305,13 +316,39 @@ module.exports = function(s,config,lang){ } break; default: - //s.systemLog(lang['Numeric criteria unsupported for Region tests, Ignoring Conditional']) - s.systemLog('Numeric criteria unsupported for Region tests, Ignoring Conditional') + s.systemLog(lang['Numeric criteria unsupported for Region tests, Ignoring Conditional']) break; } }); } break; + case'count': + if (testMatrices){ + testMatrices = compressMatrices(testMatrices) + var objectCount = testMatrices.length + switch(condition.p2){ + case'indexOf': + case'!indexOf': + s.systemLog(lang['Text criteria unsupported for Object Count tests, Ignoring Conditional']) + break; + case'===': + if(objectCount == condition.p3){ + conditionChain[place].ok = true; + } + break; + case'!==': + if(objectCount != condition.p3){ + conditionChain[place].ok = true; + } + break; + default: + if(eval(objectCount+' '+condition.p2+' "'+condition.p3.replace(/"/g,'\\"')+'"')){ + conditionChain[place].ok = true; + } + break; + } + } + break; case'time': var timeNow = new Date() var timeCondition = new Date() @@ -364,15 +401,7 @@ module.exports = function(s,config,lang){ if(filter.halt === true){ return }else if(hasMatrices){ - // remove empty elements - matchedMatrices = matchedMatrices.filter(value => Object.keys(value).length !== 0) - // remove duplicate matches - matchedMatrices = matchedMatrices.filter((matrix, index, self) => - index === self.findIndex((t) => ( - t.x === matrix.x && t.y === matrix.y && t.tag === matrix.tag && t.confidence === matrix.confidence - )) - ) - d.details.matrices = matchedMatrices + d.details.matrices = compressMatrices(matchedMatrices) } // -- delayed decision here -- if (defaultDrop && hasFilters) { @@ -414,12 +443,7 @@ module.exports = function(s,config,lang){ matchedMatrices = matchedMatrices.concat(scanMatricesforCollisions(region,testMatrices)); }) if (matchedMatrices.length > 2){ - // remove duplicate matches - matchedMatrices = matchedMatrices.filter((matrix, index, self) => - index === self.findIndex((t) => ( - t.x === matrix.x && t.y === matrix.y && t.tag === matrix.tag && t.confidence === matrix.confidence - )) - ) + matchedMatrices = compressMatrices(matchedMatrices) } d.details.matrices = matchedMatrices // pass matrices that are within a region if(d.details.matrices && d.details.matrices.length > 0){ diff --git a/web/libs/js/dash2.detectorfilter.js b/web/libs/js/dash2.detectorfilter.js index 38d2d863..7123f451 100644 --- a/web/libs/js/dash2.detectorfilter.js +++ b/web/libs/js/dash2.detectorfilter.js @@ -74,6 +74,7 @@ $(document).ready(function(e){ +