diff options
Diffstat (limited to 'check/commands/imagehash')
| -rw-r--r-- | check/commands/imagehash/add.py | 16 | ||||
| -rw-r--r-- | check/commands/imagehash/load.py | 2 | ||||
| -rw-r--r-- | check/commands/imagehash/query.py | 2 | ||||
| -rw-r--r-- | check/commands/imagehash/test.py | 2 |
4 files changed, 18 insertions, 4 deletions
diff --git a/check/commands/imagehash/add.py b/check/commands/imagehash/add.py index 37aad0d..73f8b69 100644 --- a/check/commands/imagehash/add.py +++ b/check/commands/imagehash/add.py @@ -3,8 +3,11 @@ Add a file to the database """ import click +import os -# from app.models.sql_factory import load_sql_datasets +from app.models.sql_factory import search_by_phash, add_phash +from app.utils.im_utils import compute_phash_int +from app.utils.file_utils import sha256 @click.command() @click.option('-i', '--input', 'opt_fn', @@ -18,3 +21,14 @@ def cli(ctx, opt_fn, opt_upload): Add a single file """ print('Adding a file...') + if not os.path.exists(opt_fn): + print("File does not exist") + return + + hash = sha256(opt_fn) + phash = compute_phash_int(opt_fn) + + dir, fn = os.path.split(opt_fn) + root, ext = os.path.splitext(fn) + + add_phash(sha256=hash, phash=phash, ext=ext) diff --git a/check/commands/imagehash/load.py b/check/commands/imagehash/load.py index dbb2567..e61b751 100644 --- a/check/commands/imagehash/load.py +++ b/check/commands/imagehash/load.py @@ -6,7 +6,7 @@ Loop over a directory of images import click -# from app.models.sql_factory import load_sql_datasets +from app.models.sql_factory import search_by_phash, add_phash @click.command() @click.option('-i', '--input', 'opt_dir_fn', diff --git a/check/commands/imagehash/query.py b/check/commands/imagehash/query.py index cf5c2d4..4c51324 100644 --- a/check/commands/imagehash/query.py +++ b/check/commands/imagehash/query.py @@ -4,7 +4,7 @@ Search the database for an image import click -# from app.models.sql_factory import load_sql_datasets +from app.models.sql_factory import search_by_phash, add_phash @click.command() @click.option('-i', '--input', 'opt_fn', diff --git a/check/commands/imagehash/test.py b/check/commands/imagehash/test.py index 499a424..7a38ae6 100644 --- a/check/commands/imagehash/test.py +++ b/check/commands/imagehash/test.py @@ -4,7 +4,7 @@ Query the database with a test set import click -# from app.models.sql_factory import load_sql_datasets +from app.models.sql_factory import search_by_phash, add_phash @click.command() @click.option('-i', '--input', 'opt_fn', |
