summaryrefslogtreecommitdiff
path: root/check/commands/phash/test.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-04-25 18:29:46 +0200
committerJules Laplace <julescarbon@gmail.com>2019-04-25 18:29:46 +0200
commit4d5c3d59f32b80638d82373d33a476652520e260 (patch)
tree88edd56458963229511b54276586c236604504b6 /check/commands/phash/test.py
parent4f4df4d4e38f8ce27dc7e471359f9f644ca74092 (diff)
test API
Diffstat (limited to 'check/commands/phash/test.py')
-rw-r--r--check/commands/phash/test.py49
1 files changed, 23 insertions, 26 deletions
diff --git a/check/commands/phash/test.py b/check/commands/phash/test.py
index 7fe2ae3..77c4c69 100644
--- a/check/commands/phash/test.py
+++ b/check/commands/phash/test.py
@@ -1,41 +1,38 @@
"""
-Query the database with a test set
+Test the API
"""
import click
import os
import glob
+import requests
-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
+mime_types = {
+ '.png': 'image/png',
+ '.gif': 'image/gif',
+ '.jpg': 'image/jpeg',
+ '.jpeg': 'image/jpeg',
+}
@click.command()
-@click.option('-i', '--input', 'opt_input_glob',
+@click.option('-i', '--input', 'opt_input_fn',
required=True,
- help="Input glob to search -- e.g. '../docs/images/*.jpg'")
+ help="Image to test the API with")
@click.pass_context
-def cli(ctx, opt_input_glob):
+def cli(ctx, opt_input_fn):
"""
- Query the database with a test set
+ Query the API with a test image
"""
- 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'
+ with open(opt_input_fn, 'rb') as f:
+ fn = os.path.basename(opt_input_fn)
+ fpart, ext = os.path.splitext(fn)
+ if ext not in mime_types:
+ print("Invalid filetype: {}".format(ext))
- phash_result = 'NO'
- if len(phash_match):
- phash_result = 'YES, score={}'.format(phash_match[0]['score'])
+ query = [
+ ('q', (fn, f, mime_types[ext]))
+ ]
- print("{} - hash={}, phash={}".format(fn, hash_result, phash_result))
+ print("Testing match API")
+ r = requests.post('http://0.0.0.0:5000/api/v1/match', files=query)
+ print(r.json())