-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfeba51
commit d6ec813
Showing
10 changed files
with
148 additions
and
62 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
from os.path import join | ||
import pickle | ||
from hasher.database import JsonFilesReader as DatabaseReader | ||
from hasher.extractor import Extractor | ||
|
||
def load_thresholds(fingerprints_path): | ||
db = DatabaseReader(fingerprints_path) | ||
return db.get_thresholds() | ||
|
||
def load_search_index(index_path): | ||
with open(index_path, 'rb') as f: | ||
search = pickle.load(f) | ||
return search | ||
|
||
def hash_image(img_path): | ||
hasher = Extractor() | ||
feat, th = hasher.extract2(img_path) | ||
feat = feat[None, ...] | ||
return feat | ||
|
||
if __name__ == '__main__': | ||
img_path = sys.argv[1] | ||
fingerprints_path = sys.argv[2] | ||
index_path = join(fingerprints_path, 'fingerprint.db') | ||
|
||
ths = load_thresholds(fingerprints_path) | ||
search = load_search_index(index_path) | ||
img_hash = hash_image(img_path) | ||
|
||
dist, ids = search.kneighbors(img_hash) | ||
ids = ids.squeeze() | ||
dist = dist.squeeze() | ||
|
||
if dist > ths[ids]: | ||
print('{"found": false}') | ||
else: | ||
print('{') | ||
print(' "found": true,') | ||
print(' "image": %d,' % ids) | ||
if (dist == 0.0): | ||
print(' "exact": true') | ||
else: | ||
print(' "exact": false,') | ||
print(' "distance": %f' % dist) | ||
print('}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import { listFingerprints } from '../hashDB/AngelsWings' | ||
import { fingerprintPhoto } from './fingerprint-photo' | ||
import { listFingerprintFiles } from '../hashDB/AngelsWings' | ||
import { checkPhoto } from './fingerprint-photo' | ||
import { promises as fsp } from 'fs'; | ||
|
||
async function authenticatePhoto(imagePath) { | ||
const fingerprint = await fingerprintPhoto(imagePath); | ||
const result = await checkPhoto(imagePath, '/tmp/fingerprints'); | ||
|
||
for await (const fp of listFingerprints()) { | ||
if (fingerprintMatch(fingerprint, fp.payload.fingerprint)) { | ||
fp.authentic = true; | ||
fp.payload.fingerprint = null; | ||
return fp; | ||
} | ||
} // for ... | ||
console.log(result) | ||
|
||
return { authentic: false }; | ||
if (!result.found) | ||
return { authentic: false }; | ||
|
||
const fingerprint = await loadFingerprint(result.image); | ||
fingerprint.authentic = true; | ||
fingerprint.exact = result.exact; | ||
fingerprint.distance = result.distance; | ||
fingerprint.payload.fingerprint = null; | ||
return fingerprint; | ||
} // authenticatePhoto | ||
|
||
function fingerprintMatch(lhs, rhs) { | ||
for (let i = 0; i !== lhs.hash.length; ++i) | ||
if (lhs.hash[i] !== rhs.hash[i]) | ||
return false; | ||
return true; | ||
async function loadFingerprint(index) { | ||
const imagePaths = await listFingerprintFiles(); | ||
const fingerprint = await fsp.readFile(imagePaths[index]); | ||
return JSON.parse(fingerprint); | ||
} | ||
|
||
export { authenticatePhoto }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters