videonanalysis: notes on character casing todo.

This commit is contained in:
Koushik Dutta
2024-04-18 09:56:38 -07:00
parent 47897da6fb
commit 2510fafcf7
2 changed files with 11 additions and 6 deletions

View File

@@ -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;

View File

@@ -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;