Skip to content

Commit

Permalink
fix: account for misses in camera person count
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Oct 13, 2021
1 parent cb3fb22 commit 561ec5c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions api/src/util/mqtt.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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({
Expand Down

0 comments on commit 561ec5c

Please sign in to comment.