From c86ae752e8edfa0ba8936adf5d615e533cc213d0 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 15 Sep 2023 09:02:32 -0700 Subject: [PATCH] videoanalysis: fixup spurious motion triggering object detection on a lot of cams --- plugins/objectdetector/package-lock.json | 4 ++-- plugins/objectdetector/package.json | 2 +- plugins/objectdetector/src/main.ts | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/plugins/objectdetector/package-lock.json b/plugins/objectdetector/package-lock.json index 8db853dfd..a0616c83a 100644 --- a/plugins/objectdetector/package-lock.json +++ b/plugins/objectdetector/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.166", + "version": "0.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/objectdetector", - "version": "0.0.166", + "version": "0.1.1", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/objectdetector/package.json b/plugins/objectdetector/package.json index 5baa383e0..35bfdadc9 100644 --- a/plugins/objectdetector/package.json +++ b/plugins/objectdetector/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.166", + "version": "0.1.1", "description": "Scrypted Video Analysis Plugin. Installed alongside a detection service like OpenCV or TensorFlow.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/objectdetector/src/main.ts b/plugins/objectdetector/src/main.ts index 5bc693f65..c6f858b44 100644 --- a/plugins/objectdetector/src/main.ts +++ b/plugins/objectdetector/src/main.ts @@ -161,7 +161,7 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase [...d.currentMixins.values()].filter(dd => !dd.hasMotionType)).flat() .filter(c => c.detectorRunning) .sort((a, b) => a.detectionStartTime - b.detectionStartTime); - return objectDetections.length < maxConcurrent; + // already running + if (runningDetections.find(o => o.id === mixin.id)) + return false; + + if (runningDetections.length < maxConcurrent) + return true; + + const [first] = runningDetections; + if (Date.now() - first.detectionStartTime > 30000) + return true; + + mixin.console.log(`Not starting object detection to continue processing recent activity on ${first.name}.`); + return false; } objectDetectionStarted(name: string, console: Console) {