Skip to content

Commit

Permalink
videonanalysis: notes on character casing todo.
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Apr 18, 2024
1 parent 47897da commit 2510faf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions plugins/objectdetector/src/edit-distance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// visual similarity
const similarCharacters = [
['0', 'O', 'D'],
['1', 'I'],
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 4 additions & 6 deletions plugins/objectdetector/src/smart-motionsensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2510faf

Please sign in to comment.