-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvectorize-missing.js
49 lines (40 loc) · 1.62 KB
/
vectorize-missing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const fs = require("fs")
const JSONStream = require("JSONStream")
const {sha256} = require("./src/sha256")
const {pHash1024} = require("./src/phash/phash")
const {dct1024Image} = require("./src/dct/dct")
const {intensity1024} = require("./src/intensity/intensity")
const {goldberg} = require("./src/image-signature-js/image_signature")
const {loadImageFile} = require("./src/common");
function run(name, sourceFolder, vectorizer) {
fs.readdir(sourceFolder, async (err, files) => {
const vectorGroups = {}
for (let file of files.filter(f => f.match(/.*jpg/))) {
console.error(`${name}: Processing ${file}`)
const {image, imageData} = await loadImageFile(`${sourceFolder}/${file}`)
const vectorGroup = {
file: file,
same: await vectorizer(image, imageData),
}
const sha = sha256(imageData)
vectorGroups[sha] = vectorGroup;
}
const jsonStream = JSONStream.stringifyObject();
const outputStream = fs.createWriteStream(`missing-${name}-vectors-${Date.now()}.json`);
jsonStream.pipe(outputStream)
for (const [sha, vectorGroup] of Object.entries(vectorGroups)) {
jsonStream.write([sha, vectorGroup])
}
jsonStream.end();
outputStream.on(
"finish",
function handleFinish() {
console.log("Done");
}
);
});
}
run("Goldberg","./missing-images", goldberg)
run("DCT", "./missing-images", dct1024Image)
run("Intensity", "./missing-images", intensity1024)
run("pHash", "./missing-images", pHash1024)