Skip to content

Commit

Permalink
videoanalysis: prevent double motion detector or double object detector
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 6, 2023
1 parent 7dc1f97 commit ee22686
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions plugins/objectdetector/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -187,6 +189,9 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase<VideoCamera & Camera
|| setting.value;
}

if (this.hasMotionType)
ret['motionAsObjects'] = this.storageSettings.values.motionAsObjects;

return ret;
}

Expand All @@ -212,6 +217,7 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase<VideoCamera & Camera
this.detectorRunning = false;
this.objectDetection?.detectObjects(undefined, {
detectionId: this.detectionId,
settings: this.getCurrentSettings(),
});
}

Expand Down Expand Up @@ -483,6 +489,7 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase<VideoCamera & Camera
await this.objectDetection?.detectObjects(undefined, {
detectionId: this.detectionId,
duration: this.getDetectionDuration(),
settings: this.getCurrentSettings(),
}, this);
}
catch (e) {
Expand Down Expand Up @@ -774,7 +781,7 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase<VideoCamera & Camera
const settings: Setting[] = [];

try {
this.settings = (await this.objectDetection.getDetectionModel(this.settings)).settings;
this.settings = (await this.objectDetection.getDetectionModel(this.getCurrentSettings())).settings;
}
catch (e) {
}
Expand Down Expand Up @@ -1006,40 +1013,39 @@ class ObjectDetectorMixin extends MixinDeviceBase<ObjectDetection> implements Mi
}

async canMixin(type: ScryptedDeviceType, interfaces: string[]): Promise<string[]> {
// 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<ObjectDetection>(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);
Expand Down

0 comments on commit ee22686

Please sign in to comment.