diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 16:26:03 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 16:26:03 +0200 |
| commit | 79f0e696f3f6067a0841a37404fb546dedaa07cb (patch) | |
| tree | a064f2841dc532f81fcf04eb84300e679fda2b27 /check/commands/phash/test.py | |
| parent | e257e83f313a2976347b0a30f58e66b7bcbc1235 (diff) | |
cli suite working
Diffstat (limited to 'check/commands/phash/test.py')
| -rw-r--r-- | check/commands/phash/test.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/check/commands/phash/test.py b/check/commands/phash/test.py new file mode 100644 index 0000000..7fe2ae3 --- /dev/null +++ b/check/commands/phash/test.py @@ -0,0 +1,41 @@ +""" +Query the database with a test set +""" + +import click +import os +import glob + +from PIL import Image + +from app.models.sql_factory import search_by_phash, search_by_hash +from app.utils.im_utils import compute_phash_int +from app.utils.file_utils import sha256 + +@click.command() +@click.option('-i', '--input', 'opt_input_glob', + required=True, + help="Input glob to search -- e.g. '../docs/images/*.jpg'") +@click.pass_context +def cli(ctx, opt_input_glob): + """ + Query the database with a test set + """ + for fn in sorted(glob.iglob(opt_input_glob)): + im = Image.open(fn).convert('RGB') + phash = compute_phash_int(im) + + hash = sha256(fn) + + phash_match = search_by_phash(phash) + hash_match = search_by_hash(hash) + + hash_result = 'NO' + if hash_match: + hash_result = 'YES' + + phash_result = 'NO' + if len(phash_match): + phash_result = 'YES, score={}'.format(phash_match[0]['score']) + + print("{} - hash={}, phash={}".format(fn, hash_result, phash_result)) |
