From 561ec5c2998af1502eec82a31c751394f7b9a1e8 Mon Sep 17 00:00:00 2001 From: David Jakowenko Date: Wed, 13 Oct 2021 00:23:14 -0400 Subject: [PATCH] fix: account for misses in camera person count --- api/src/util/mqtt.util.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/api/src/util/mqtt.util.js b/api/src/util/mqtt.util.js index 13a6a226..05f08645 100644 --- a/api/src/util/mqtt.util.js +++ b/api/src/util/mqtt.util.js @@ -141,7 +141,7 @@ module.exports.subscribe = () => { module.exports.recognize = (data) => { try { if (!MQTT || !MQTT.HOST) return; - const { matches, unknown, camera } = data; + const { matches, misses, unknown, camera } = data; const hasUnknown = unknown && Object.keys(unknown).length; const configData = JSON.parse(JSON.stringify(data)); @@ -150,17 +150,23 @@ module.exports.recognize = (data) => { delete configData.results; const messages = []; - - let personCount = matches.length ? matches.length : hasUnknown ? 1 : 0; + const persons = [...new Set([...matches, ...misses].map(({ name }) => name))]; + let personCount = persons.length ? persons.length : hasUnknown ? 1 : 0; // check to see if unknown bounding box is contained within or contains any of the match bounding boxes // if false, then add 1 to the person count - if (matches.length && hasUnknown) { - let unknownContained = false; + if (persons.length && hasUnknown) { + let unknownFoundInMatch = false; matches.forEach((match) => { if (contains(match.box, unknown.box) || contains(unknown.box, match.box)) - unknownContained = true; + unknownFoundInMatch = true; + }); + + let unknownFoundInMiss = false; + misses.forEach((miss) => { + if (contains(miss.box, unknown.box) || contains(unknown.box, miss.box)) + unknownFoundInMiss = true; }); - if (!unknownContained) personCount += 1; + if (!unknownFoundInMatch && !unknownFoundInMiss) personCount += 1; } messages.push({