From f0ee435cd0bc37eccf1d402f721d71331fb4e793 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 10 Apr 2023 17:49:33 -0700 Subject: [PATCH] videoanalysis: fix detection calculation/throttling in snapshot mode --- plugins/objectdetector/package-lock.json | 4 +-- plugins/objectdetector/package.json | 2 +- plugins/objectdetector/src/main.ts | 31 +++++++++++++----------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/plugins/objectdetector/package-lock.json b/plugins/objectdetector/package-lock.json index 54d6fd9db..85f2a1a65 100644 --- a/plugins/objectdetector/package-lock.json +++ b/plugins/objectdetector/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.127", + "version": "0.0.128", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/objectdetector", - "version": "0.0.127", + "version": "0.0.128", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/objectdetector/package.json b/plugins/objectdetector/package.json index 44eb5d468..8cf9d90a7 100644 --- a/plugins/objectdetector/package.json +++ b/plugins/objectdetector/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.127", + "version": "0.0.128", "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 3ead86faf..01200d40a 100644 --- a/plugins/objectdetector/src/main.ts +++ b/plugins/objectdetector/src/main.ts @@ -262,16 +262,15 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase this.plugin.trackDetection(), + snapshotPipeline: this.plugin.shouldUseSnapshotPipeline(), }; - const start = Date.now(); this.runPipelineAnalysis(signal, options) .catch(e => { this.console.error('Video Analysis ended with error', e); }).finally(() => { if (!this.hasMotionType) - this.plugin.objectDetectionEnded(this.console); + this.plugin.objectDetectionEnded(this.console, options.snapshotPipeline); else this.console.log('Video Analysis motion detection ended.'); signal.resolve(); @@ -279,7 +278,7 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase, options: { - onObjectDetection: () => void, + snapshotPipeline: boolean, }) { const start = Date.now(); this.analyzeStop = start + this.getDetectionDuration(); @@ -303,13 +302,14 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase 10000 && this.statsSnapshotDetections) { + // ignore short sessions and sessions with no detections (busted?). + // also ignore snapshot sessions because that will skew/throttle the stats used + // to determine system dps capabilities. + if (duration > 10000 && this.statsSnapshotDetections && !snapshotPipeline) this.objectDetectionStatistics.set(concurrentSessions, stats); - this.pruneOldStatistics(); - } + + this.pruneOldStatistics(); const str = `video analysis, ${concurrentSessions} camera(s), dps: ${Math.round(stats.dps * 10) / 10} (${this.statsSnapshotDetections}/${Math.round(duration / 1000)})`; this.console.log(str);