videoanalysis: fixup spurious motion triggering object detection on a lot of cams

This commit is contained in:
Koushik Dutta
2023-09-15 09:02:32 -07:00
parent b7ca477b98
commit c86ae752e8
3 changed files with 19 additions and 7 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -161,7 +161,7 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase<VideoCamera & Camera
maybeStartDetection() {
if (!this.hasMotionType) {
// object detection may be restarted if there are slots available.
if (this.cameraDevice.motionDetected && this.plugin.canStartObjectDetection())
if (this.cameraDevice.motionDetected && this.plugin.canStartObjectDetection(this))
this.startPipelineAnalysis();
return;
}
@@ -1074,15 +1074,27 @@ class ObjectDetectionPlugin extends AutoenableMixinProvider implements Settings,
return maxConcurrent;
}
canStartObjectDetection() {
canStartObjectDetection(mixin: ObjectDetectionMixin) {
const maxConcurrent = this.maxConcurrent;
const objectDetections = [...this.currentMixins.values()]
const runningDetections = [...this.currentMixins.values()]
.map(d => [...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) {