videoanalysis: add zone choices to smart sensor

This commit is contained in:
Koushik Dutta
2023-12-07 22:35:15 -08:00
parent e3ecff04ce
commit c98e91cd39
4 changed files with 19 additions and 8 deletions

View File

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

View File

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

View File

@@ -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<ObjectDetectorMixin>();
objectDetectionStatistics = new Map<number, ObjectDetectionStatistics>();
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;

View File

@@ -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],
};
};