From e9ab49c60a8a0707a4744d2a6e058fe5ade56364 Mon Sep 17 00:00:00 2001
From: Damien De Paoli
Date: Sun, 6 Feb 2022 23:21:23 +1100
Subject: [PATCH] with viewer, unmatched face now has img data / thumbnail, so
we know what it really looks like when we choose to override - still major
WIP, tables.sql also has some override types, but not convinced I have design
yet
---
TODO | 1 +
ai.py | 24 ++++++++++++++++++++++++
internal/js/view_support.js | 37 +++++++++++++++++++++++++------------
tables.sql | 15 +++++++++++++++
templates/viewer.html | 1 +
5 files changed, 66 insertions(+), 12 deletions(-)
diff --git a/TODO b/TODO
index b47e9f6..1145a38 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,5 @@
## GENERAL
+ * run_ai_on throws log line, for matching even if there are no faces, would be less noisy to not do that (or should say no faces?)
* on viewer:
- allow face to be used to create person, add to existing person, and allow 'ignore', mark as 'not a face', etc
-> ignore/not a face/too young --> all need to go into DB so we can remember the 'override' when we re-ai-match
diff --git a/ai.py b/ai.py
index c893626..4e79732 100644
--- a/ai.py
+++ b/ai.py
@@ -105,3 +105,27 @@ def unmatched_faces():
face.img = str(face.img)[2:-1]
return render_template("faces.html", faces=faces)
+
+
+# this is called in Ajax, when we manually override a face that is currently unmatched load
+# the original full image, find the current face's coords, grab pixels 10% larger and return
+# it so we can show it in the dbox, and be able to pass it around for refimg creation (if needed)
+@app.route("/get_face_from_image/", methods=["POST"])
+@login_required
+def get_face_from_image(face_id):
+ face=Face.query.get(face_id)
+ f = Entry.query.join(File).join(FaceFileLink).filter(FaceFileLink.face_id==face_id).first()
+ tmp_locn=json.loads(face.locn)
+ x=tmp_locn[3]*0.95
+ y=tmp_locn[0]*0.95
+ x2=tmp_locn[1]*1.05
+ y2=tmp_locn[2]*1.05
+
+ im = Image.open(f.FullPathOnFS())
+ region = im.crop((x, y, x2, y2))
+ img_bytearray = io.BytesIO()
+ region.save(img_bytearray, format='JPEG')
+ img_bytearray = img_bytearray.getvalue()
+ face_img = base64.b64encode(img_bytearray)
+ face_img = str(face_img)[2:-1]
+ return face_img
diff --git a/internal/js/view_support.js b/internal/js/view_support.js
index 9a6c7b0..f1fcbc0 100644
--- a/internal/js/view_support.js
+++ b/internal/js/view_support.js
@@ -204,8 +204,8 @@ $(document).ready( function()
$.contextMenu({
selector: '#canvas',
-// trigger: 'left',
- trigger: 'none',
+ trigger: 'left',
+// trigger: 'none',
hideOnSecondTrigger: true,
build: function($triggerElement, e) {
@@ -226,16 +226,16 @@ $(document).ready( function()
if( x >= fx && x <= fx+fw && y >= fy && y <= fy+fh )
{
if( objs[current].faces[i].who )
- item_list['match']={ 'name': objs[current].faces[i].who, 'which_face': i }
+ item_list['match']={ 'name': objs[current].faces[i].who, 'which_face': i, 'id': objs[current].faces[i].id }
else
{
- item_list['no_match_new_person']={ 'name': 'Add as reference image to NEW person', 'which_face': i }
- item_list['no_match_new_refimg']={ 'name': 'Add as reference image to EXISTING person', 'which_face': i }
- item_list['no_match_override_match']={ 'name': 'Manually match to existing person', 'which_face': i }
- item_list['no_match_no_face']={ 'name': 'Mark as not a face', 'which_face': i }
- item_list['no_match_too_young']={ 'name': 'Mark as face too young', 'which_face': i }
- item_list['no_match_ignore']={ 'name': 'Ignore this face', 'which_face': i }
- item_list['remove_override']={ 'name': 'Remove override for this face', 'which_face': i }
+ item_list['no_match_new_person']={ 'name': 'Add as reference image to NEW person', 'which_face': i, 'id': objs[current].faces[i].id }
+ item_list['no_match_new_refimg']={ 'name': 'Add as reference image to EXISTING person', 'which_face': i, 'id': objs[current].faces[i].id }
+ item_list['no_match_override_match']={ 'name': 'Manually match to existing person', 'which_face': i, 'id': objs[current].faces[i].id }
+ item_list['no_match_no_face']={ 'name': 'Mark as not a face', 'which_face': i, 'id': objs[current].faces[i].id }
+ item_list['no_match_too_young']={ 'name': 'Mark as face too young', 'which_face': i, 'id': objs[current].faces[i].id }
+ item_list['no_match_ignore']={ 'name': 'Ignore this face', 'which_face': i, 'id': objs[current].faces[i].id }
+ item_list['remove_override']={ 'name': 'Remove override for this face', 'which_face': i, 'id': objs[current].faces[i].id }
}
delete item_list['not_a_face']
$('#canvas').prop('menu_item', item_list )
@@ -258,7 +258,13 @@ $(document).ready( function()
function FaceDBox(key, item)
{
div ='