Add support for testing count of matched objects

merge-requests/210/head
dennis.cartier 2020-06-26 05:43:36 -04:00
parent 5c19166125
commit 5ddfbcb5d3
3 changed files with 46 additions and 18 deletions

View File

@ -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",

View File

@ -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){

View File

@ -74,6 +74,7 @@ $(document).ready(function(e){
<option value="plug">${lang['Detection Engine']}</option>
<optgroup label="Matrix">
<option value="tag">${lang['Object Tag']}</option>
<option value="count">${lang['Object Count']}</option>
<option value="confidence">${lang['Confidence']}</option>
<option value="x">${lang['X Point']}</option>
<option value="y">${lang['Y Point']}</option>