From 8773af1b0b4db70426c8ca647dee60f67e28fdb0 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 14 Jan 2023 18:14:48 -0800 Subject: [PATCH] videoanalysis: fix detection expiration. --- plugins/objectdetector/src/denoise.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/objectdetector/src/denoise.ts b/plugins/objectdetector/src/denoise.ts index 0e7be4c24..d0d910683 100644 --- a/plugins/objectdetector/src/denoise.ts +++ b/plugins/objectdetector/src/denoise.ts @@ -96,6 +96,8 @@ export function denoiseDetections(state: DenoisedDetectionState, state.previousDetections = []; const now = options.now || Date.now(); + const lastDetection = state.lastDetection || now; + const sinceLastDetection = now - lastDetection; const externallyTracked = currentDetections.filter(d => d.id); if (externallyTracked.length) { @@ -122,9 +124,12 @@ export function denoiseDetections(state: DenoisedDetectionState, } } - for (const tracked of state.externallyTracked.values()) { - if (now - tracked.lastSeen > options.timeout) { - options?.expiring(tracked); + for (const previous of state.externallyTracked.values()) { + if (now - previous.lastSeen) { + previous.durationGone += sinceLastDetection; + if (previous.durationGone >= options.timeout) { + options?.expiring(previous); + } } } } @@ -151,8 +156,6 @@ export function denoiseDetections(state: DenoisedDetectionState, // } - const lastDetection = state.lastDetection || now; - const sinceLastDetection = now - lastDetection; const previousCopy = previousDetections.slice(); previousDetections.splice(0, previousDetections.length); const map = new Map>();