🛣 Levenshtein distance between images WIP

This commit is contained in:
2021-07-31 12:02:47 -07:00
parent fcb922d52b
commit 51d8f94068
5 changed files with 408 additions and 4 deletions

View File

@@ -1,4 +1,8 @@
const sharp = require("sharp");
const imghash = require("imghash");
const leven = require("leven");
import path from "path";
import { isNull, reject } from "lodash";
import { logger } from "./logger.utils";
export const extractMetadataFromImage = async (
@@ -32,3 +36,20 @@ export const resizeImage = async (
return info;
});
};
export const calculateLevenshteinDistance = async (
imagePath1: string,
imagePath2: string
): Promise<Record<string, unknown>> => {
console.log("AGANTUK", imagePath1)
const hash1 = await imghash.hash(imagePath1);
const hash2 = await imghash.hash(imagePath2);
console.log("HASHISH", hash1)
if (!isNull(hash1) && !isNull(hash2)) {
return new Promise((resolve, reject) => {
resolve({ levenshteinDistance: leven(hash1, hash2) });
});
} else {
reject("Can't calculate the Levenshtein distance")
}
};