From 9fac5535780165d08a7718f5bb3efb81e03434b4 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 22 Dec 2021 22:07:20 -0800 Subject: [PATCH] objectdetector: add object detect types from mixined device --- plugins/objectdetector/package-lock.json | 4 +- plugins/objectdetector/package.json | 2 +- plugins/objectdetector/src/main.ts | 114 +++++++++++++++++++---- 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/plugins/objectdetector/package-lock.json b/plugins/objectdetector/package-lock.json index 8f8608be5..059017df8 100644 --- a/plugins/objectdetector/package-lock.json +++ b/plugins/objectdetector/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.33", + "version": "0.0.35", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/objectdetector", - "version": "0.0.33", + "version": "0.0.35", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/objectdetector/package.json b/plugins/objectdetector/package.json index 0db6a274c..9dc98717c 100644 --- a/plugins/objectdetector/package.json +++ b/plugins/objectdetector/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.33", + "version": "0.0.35", "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 767d92e78..debf38450 100644 --- a/plugins/objectdetector/src/main.ts +++ b/plugins/objectdetector/src/main.ts @@ -19,6 +19,10 @@ const defaultDetectionInterval = 60; const defaultDetectionTimeout = 10; const defaultMotionDuration = 10; +const DETECT_PERIODIC_SNAPSHOTS = "Periodic Snapshots"; +const DETECT_MOTION_SNAPSHOTS = "Motion Snapshots"; +const DETECT_VIDEO_MOTION = "Video Motion"; + type ClipPath = [number, number][]; type Zones = { [zone: string]: ClipPath }; @@ -26,8 +30,11 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase(); cameraDevice: ScryptedDevice & Camera & VideoCamera & MotionSensor; + detectSnapshotsOnly = this.storage.getItem('detectionMode'); + detectionModes = this.getDetectionModes(); detectionTimeout = parseInt(this.storage.getItem('detectionTimeout')) || defaultDetectionTimeout; detectionDuration = parseInt(this.storage.getItem('detectionDuration')) || defaultDetectionDuration; motionDuration = parseInt(this.storage.getItem('motionDuration')) || defaultMotionDuration; @@ -59,6 +66,19 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase { - if (!this.running) - this.snapshotDetection(); + if (!this.running) { + if (this.detectionModes.includes(DETECT_PERIODIC_SNAPSHOTS)) + this.snapshotDetection(); + } }, this.detectionInterval * 1000); } @@ -127,6 +149,8 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase { + if (!eventData?.detections?.find(d => d.className === 'motion')) + return; + if (!eventData?.eventId) + return; + const od = eventSource as any as ObjectDetector; + const mo = await od.getDetectionInput(eventData.detectionId, eventData.eventId); + const detections = await this.objectDetection.detectObjects(mo, { + detectionId: this.detectionId, + settings: await this.getCurrentSettings(), + }); + this.objectsDetected(detections, true); + }); + } } async register() { @@ -151,7 +192,8 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase { - return this.objectDetection.getDetectionModel(); + const ret = await this.getNativeObjectTypes(); + if (!ret.classes) + ret.classes = []; + ret.classes.push(...(await this.objectDetection.getDetectionModel()).classes); + return ret; } async getDetectionInput(detectionId: any): Promise { @@ -345,21 +391,45 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase