summaryrefslogtreecommitdiff
path: root/check/app/server/api.py
diff options
context:
space:
mode:
Diffstat (limited to 'check/app/server/api.py')
-rw-r--r--check/app/server/api.py20
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 })