diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 13:35:21 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 13:35:21 +0200 |
| commit | 229ddbb5cbf228b13b44ecaa10ef931c68b97e5c (patch) | |
| tree | bd3f095d57b8b8252551b6bc61ec3f3e9d53f146 /check/app/server/api.py | |
| parent | 7a1f5eb87d71acd5466b08a23ee0f98ea7edf28c (diff) | |
query api
Diffstat (limited to 'check/app/server/api.py')
| -rw-r--r-- | check/app/server/api.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/check/app/server/api.py b/check/app/server/api.py index 12d955b..6b97b59 100644 --- a/check/app/server/api.py +++ b/check/app/server/api.py @@ -7,6 +7,7 @@ from PIL import Image # from app.utils.im_utils import pil2np from app.models.sql_factory import search_by_phash, add_phash +from app.utils.im_utils import pil2np sanitize_re = re.compile('[\W]+') valid_exts = ['.gif', '.jpg', '.jpeg', '.png'] @@ -24,5 +25,22 @@ def index(): def upload(): """Search by image""" start = time.time() + + file = request.files['query_img'] + fn = file.filename + if fn.endswith('blob'): # FIX PNG IMAGES? + fn = 'filename.jpg' + + basename, ext = os.path.splitext(fn) + if ext.lower() not in valid_exts: + return jsonify({ + 'error': 'not_an_image' + }) + + im = Image.open(file.stream).convert('RGB') + im_np = pil2np(im) + + res = search_by_phash(im_np) + # get threshold - return jsonify({ 'status': 'ok' }) + return jsonify({ 'res': res }) |
