Skip to content

Commit

Permalink
videoanalysis: label scores
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed May 30, 2024
1 parent 227f932 commit e3cdd43
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions plugins/objectdetector/src/smart-motionsensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export class SmartMotionSensor extends ScryptedDeviceBase implements Settings, R
type: 'number',
defaultValue: 2,
},
labelScore: {
group: 'Recognition',
title: 'Label Score',
description: 'The minimum score required for a label to trigger the motion sensor.',
type: 'number',
defaultValue: 0,
}
});

detectionListener: EventListenerRegister;
Expand Down Expand Up @@ -190,7 +197,7 @@ export class SmartMotionSensor extends ScryptedDeviceBase implements Settings, R
if (this.storageSettings.values.requireDetectionThumbnail && !detected.detectionId)
return false;

const { labels, labelDistance } = this.storageSettings.values;
const { labels, labelDistance, labelScore } = this.storageSettings.values;

const match = detected.detections?.find(d => {
if (this.storageSettings.values.requireScryptedNvrDetections && !d.boundingBox)
Expand Down Expand Up @@ -225,13 +232,24 @@ export class SmartMotionSensor extends ScryptedDeviceBase implements Settings, R
return false;

for (const label of labels) {
if (label === d.label)
return true;
if (label === d.label) {
if (!labelScore || d.labelScore >= labelScore)
return true;
this.console.log('Label score too low.', label, d.label, d.labelScore);
continue;
}

if (!labelDistance)
continue;
if (levenshteinDistance(label, d.label) <= labelDistance)

if (levenshteinDistance(label, d.label) > labelDistance) {
this.console.log('Label does not match.', label, d.label, d.labelScore);
continue;
}

if (!labelScore || d.labelScore >= labelScore)
return true;
this.console.log('Label does not match.', label, d.label);
this.console.log('Label score too low.', label, d.label, d.labelScore);
}

return false;
Expand Down

0 comments on commit e3cdd43

Please sign in to comment.