From ee22686bffb54ffa47f27a4e2b208ed46e444d5b Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 6 Mar 2023 10:32:35 -0800 Subject: [PATCH] videoanalysis: prevent double motion detector or double object detector --- plugins/objectdetector/src/main.ts | 46 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/plugins/objectdetector/src/main.ts b/plugins/objectdetector/src/main.ts index 2f5c1ebbb9..b3eea42374 100644 --- a/plugins/objectdetector/src/main.ts +++ b/plugins/objectdetector/src/main.ts @@ -24,6 +24,8 @@ const defaultSecondScoreThreshold = .7; const BUILTIN_MOTION_SENSOR_ASSIST = 'Assist'; const BUILTIN_MOTION_SENSOR_REPLACE = 'Replace'; +const objectDetectionPrefix = `${ScryptedInterface.ObjectDetection}:`; + type ClipPath = [number, number][]; type Zones = { [zone: string]: ClipPath }; interface ZoneInfo { @@ -187,6 +189,9 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase implements Mi } async canMixin(type: ScryptedDeviceType, interfaces: string[]): Promise { - // filter out - for (const iface of interfaces) { - if (iface.startsWith(`${ScryptedInterface.ObjectDetection}:`)) { - const deviceMatch = this.mixinDeviceInterfaces.find(miface => miface.startsWith(iface)); - if (deviceMatch) - continue; - return null; - } - } + const hasMotionType = this.model.classes.includes('motion'); + const prefix = `${objectDetectionPrefix}${hasMotionType}`; + const thisPrefix = `${prefix}:${this.id}`; + + const found = interfaces.find(iface => iface.startsWith(prefix) && iface !== thisPrefix); + if (found) + return; + // this.console.log('found', found); if ((type === ScryptedDeviceType.Camera || type === ScryptedDeviceType.Doorbell) && (interfaces.includes(ScryptedInterface.VideoCamera) || interfaces.includes(ScryptedInterface.Camera))) { - const ret: string[] = [ScryptedInterface.ObjectDetector, ScryptedInterface.Settings]; + const ret: string[] = [ + ScryptedInterface.ObjectDetector, + ScryptedInterface.Settings, + thisPrefix, + ]; const model = await this.mixinDevice.getDetectionModel(); - if (model.classes?.includes('motion')) { - // const vamotion = 'mixin:@scrypted/objectdetector:motion'; - // if (interfaces.includes(vamotion)) - // return; + if (model.classes?.includes('motion')) { ret.push( ScryptedInterface.MotionSensor, - // vamotion, ); } - return ret; + return ret; } - return null; } async getMixin(mixinDevice: any, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: { [key: string]: any }) { let objectDetection = systemManager.getDeviceById(this.id); - const group = objectDetection.name.replace('Plugin', '').trim(); - const hasMotionType = this.model.classes.includes('motion'); + const group = hasMotionType ? 'Motion Detection' : 'Object Detection'; + // const group = objectDetection.name.replace('Plugin', '').trim(); + const settings = this.model.settings; const ret = new ObjectDetectionMixin(mixinDevice, mixinDeviceInterfaces, mixinDeviceState, this.mixinProviderNativeId, objectDetection, this.model.name, group, hasMotionType, settings);