From c98e91cd39dce2c3cdcc1ee05f53941a2a117a2e Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 7 Dec 2023 22:35:15 -0800 Subject: [PATCH] videoanalysis: add zone choices to smart sensor --- plugins/objectdetector/package-lock.json | 4 ++-- plugins/objectdetector/package.json | 2 +- plugins/objectdetector/src/main.ts | 6 +++--- plugins/objectdetector/src/smart-motionsensor.ts | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/plugins/objectdetector/package-lock.json b/plugins/objectdetector/package-lock.json index 8abcb7229..579598011 100644 --- a/plugins/objectdetector/package-lock.json +++ b/plugins/objectdetector/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/objectdetector", - "version": "0.1.13", + "version": "0.1.14", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/objectdetector", - "version": "0.1.13", + "version": "0.1.14", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/objectdetector/package.json b/plugins/objectdetector/package.json index 4492cf949..272338abf 100644 --- a/plugins/objectdetector/package.json +++ b/plugins/objectdetector/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/objectdetector", - "version": "0.1.13", + "version": "0.1.14", "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 0a01f7c71..901a905ec 100644 --- a/plugins/objectdetector/src/main.ts +++ b/plugins/objectdetector/src/main.ts @@ -898,7 +898,7 @@ interface ObjectDetectionStatistics { sampleTime: number; } -class ObjectDetectionPlugin extends AutoenableMixinProvider implements Settings, DeviceProvider, DeviceCreator { +export class ObjectDetectionPlugin extends AutoenableMixinProvider implements Settings, DeviceProvider, DeviceCreator { currentMixins = new Set(); objectDetectionStatistics = new Map(); statsSnapshotTime: number; @@ -1105,7 +1105,7 @@ class ObjectDetectionPlugin extends AutoenableMixinProvider implements Settings, if (nativeId === 'ffmpeg') ret = this.devices.get(nativeId) || new FFmpegVideoFrameGenerator('ffmpeg'); if (nativeId?.startsWith(SMART_MOTIONSENSOR_PREFIX)) - ret = this.devices.get(nativeId) || new SmartMotionSensor(nativeId); + ret = this.devices.get(nativeId) || new SmartMotionSensor(this, nativeId); if (ret) this.devices.set(nativeId, ret); @@ -1172,7 +1172,7 @@ class ObjectDetectionPlugin extends AutoenableMixinProvider implements Settings, ] }); - const sensor = new SmartMotionSensor(nativeId); + const sensor = new SmartMotionSensor(this, nativeId); sensor.storageSettings.values.objectDetector = objectDetector?.id; return id; diff --git a/plugins/objectdetector/src/smart-motionsensor.ts b/plugins/objectdetector/src/smart-motionsensor.ts index f14c674a5..25707e1cd 100644 --- a/plugins/objectdetector/src/smart-motionsensor.ts +++ b/plugins/objectdetector/src/smart-motionsensor.ts @@ -1,5 +1,6 @@ import sdk, { EventListenerRegister, MotionSensor, ObjectDetector, ObjectsDetected, Readme, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, ScryptedNativeId, Setting, SettingValue, Settings } from "@scrypted/sdk"; import { StorageSetting, StorageSettings } from "@scrypted/sdk/storage-settings"; +import type { ObjectDetectionPlugin } from "./main"; export const SMART_MOTIONSENSOR_PREFIX = 'smart-motionsensor-'; @@ -40,7 +41,7 @@ export class SmartMotionSensor extends ScryptedDeviceBase implements Settings, R listener: EventListenerRegister; timeout: NodeJS.Timeout; - constructor(nativeId?: ScryptedNativeId) { + constructor(public plugin: ObjectDetectionPlugin, nativeId?: ScryptedNativeId) { super(nativeId); this.storageSettings.settings.detections.onGet = async () => { @@ -59,8 +60,18 @@ export class SmartMotionSensor extends ScryptedDeviceBase implements Settings, R this.storageSettings.settings.zones.onPut = () => this.rebind(); this.storageSettings.settings.zones.onGet = async () => { + const objectDetector: ObjectDetector & ScryptedDevice = this.storageSettings.values.objectDetector; + const objectDetections = [...this.plugin.currentMixins.values()] + .map(d => [...d.currentMixins.values()].filter(dd => !dd.hasMotionType)).flat(); + + const mixin = objectDetections.find(m => m.id === objectDetector?.id); + const zones = new Set(Object.keys(mixin?.getZones() || {})); + for (const z of this.storageSettings.values.zones || []) { + zones.add(z); + } + return { - choices: this.storageSettings.values.zones || [], + choices: [...zones], }; };