diff --git a/plugins/objectdetector/src/edit-distance.ts b/plugins/objectdetector/src/edit-distance.ts index be9430c162..e598b1e94c 100644 --- a/plugins/objectdetector/src/edit-distance.ts +++ b/plugins/objectdetector/src/edit-distance.ts @@ -1,3 +1,4 @@ +// visual similarity const similarCharacters = [ ['0', 'O', 'D'], ['1', 'I'], @@ -32,6 +33,12 @@ function isSameCharacter(c1: string, c2: string) { } export function levenshteinDistance(str1: string, str2: string): number { + // todo: handle lower/uppercase similarity in similarCharacters above. + // ie, b is visualy similar to 6, but does not really look like B. + // others include e and C. v, u and Y. l, i, 1. + str1 = str1.toUpperCase(); + str2 = str2.toUpperCase(); + const len1 = str1.length; const len2 = str2.length; diff --git a/plugins/objectdetector/src/smart-motionsensor.ts b/plugins/objectdetector/src/smart-motionsensor.ts index bbe43bac5a..5cafc3c27e 100644 --- a/plugins/objectdetector/src/smart-motionsensor.ts +++ b/plugins/objectdetector/src/smart-motionsensor.ts @@ -173,8 +173,7 @@ export class SmartMotionSensor extends ScryptedDeviceBase implements Settings, R if (this.storageSettings.values.requireDetectionThumbnail && !detected.detectionId) return false; - let { labels, labelDistance } = this.storageSettings.values; - labels = labels?.map((l: string) => l.toUpperCase()); + const { labels, labelDistance } = this.storageSettings.values; const match = detected.detections?.find(d => { if (this.storageSettings.values.requireScryptedNvrDetections && !d.boundingBox) @@ -208,15 +207,14 @@ export class SmartMotionSensor extends ScryptedDeviceBase implements Settings, R if (!d.label) return false; - const du = d.label.toUpperCase(); for (const label of labels) { - if (label === du) + if (label === d.label) return true; if (!labelDistance) continue; - if (levenshteinDistance(label, du) <= labelDistance) + if (levenshteinDistance(label, d.label) <= labelDistance) return true; - this.console.log('No label does not match.', label, du); + this.console.log('No label does not match.', label, d.label); } return false;