videoanalysis: fix detection expiration.

This commit is contained in:
Koushik Dutta
2023-01-14 18:14:48 -08:00
parent 7b4b2d1356
commit 8773af1b0b

View File

@@ -96,6 +96,8 @@ export function denoiseDetections<T>(state: DenoisedDetectionState<T>,
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<T>(state: DenoisedDetectionState<T>,
}
}
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<T>(state: DenoisedDetectionState<T>,
// }
const lastDetection = state.lastDetection || now;
const sinceLastDetection = now - lastDetection;
const previousCopy = previousDetections.slice();
previousDetections.splice(0, previousDetections.length);
const map = new Map<string, DenoisedDetectionEntry<T>>();