now can create a new person and refimg from viewer - all works
This commit is contained in:
4
TODO
4
TODO
@@ -1,9 +1,9 @@
|
|||||||
## GENERAL
|
## GENERAL
|
||||||
* on viewer:
|
* on viewer:
|
||||||
- allow face to be used to:
|
- allow face to be used to:
|
||||||
- create person
|
[DONE] - create person
|
||||||
[DONE] - add to existing person
|
[DONE] - add to existing person
|
||||||
--> still need to consider whether we trigger an AI search immediately
|
--> still need to consider whether we trigger an AI search immediately (for these 2 options)
|
||||||
[DONE] - ignore/not a face/too young
|
[DONE] - ignore/not a face/too young
|
||||||
[DONE] - redraw 'ignore's as a greyed out box?
|
[DONE] - redraw 'ignore's as a greyed out box?
|
||||||
[DONE] - menu should only allow override IF we have put override on...
|
[DONE] - menu should only allow override IF we have put override on...
|
||||||
|
|||||||
@@ -291,11 +291,27 @@ function OverrideForceMatch( person_id, key )
|
|||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CreatePersonAndRefimg( key )
|
||||||
|
{
|
||||||
|
d='&face_id='+item[key].id
|
||||||
|
+'&tag='+$('#tag').val()
|
||||||
|
+'&firstname='+$('#firstname').val()
|
||||||
|
+'&surname='+$('#surname').val()
|
||||||
|
+'&refimg_data='+item[key].refimg_data
|
||||||
|
$.ajax({ type: 'POST', data: d, url: '/match_with_create_person',
|
||||||
|
success: function(data) {
|
||||||
|
objs[current].faces[item[key].which_face].who=data.who
|
||||||
|
objs[current].faces[item[key].which_face].distance=data.distance
|
||||||
|
$('#dbox').modal('hide')
|
||||||
|
$('#faces').prop('checked',true)
|
||||||
|
DrawImg()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function AddRefImgTo( person_id, key )
|
function AddRefImgTo( person_id, key )
|
||||||
{
|
{
|
||||||
d='&face_id='+item[key].id+'&person_id='+person_id+
|
d='&face_id='+item[key].id+'&person_id='+person_id+'&refimg_data='+item[key].refimg_data
|
||||||
'&file_eid='+current+'&refimg_data='+item[key].refimg_data
|
|
||||||
console.log( d )
|
|
||||||
$.ajax({ type: 'POST', data: d, url: '/add_refimg_to_person',
|
$.ajax({ type: 'POST', data: d, url: '/add_refimg_to_person',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
objs[current].faces[item[key].which_face].who=data.who
|
objs[current].faces[item[key].which_face].who=data.who
|
||||||
@@ -411,6 +427,9 @@ function FaceDBox(key, item)
|
|||||||
success: function(img_data) {
|
success: function(img_data) {
|
||||||
item[key].refimg_data=img_data
|
item[key].refimg_data=img_data
|
||||||
$('#face_img').html( '<img src="data:image/jpeg;base64,' + img_data + '"></img>' )
|
$('#face_img').html( '<img src="data:image/jpeg;base64,' + img_data + '"></img>' )
|
||||||
|
// used for create_new_person only, so this will do nothing for
|
||||||
|
// option menu items
|
||||||
|
$('#refimg_data').val(img_data)
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
div+='</p></div><div class="col-6">'
|
div+='</p></div><div class="col-6">'
|
||||||
@@ -431,7 +450,24 @@ function FaceDBox(key, item)
|
|||||||
}
|
}
|
||||||
if ( key == 'no_match_new_person' )
|
if ( key == 'no_match_new_person' )
|
||||||
{
|
{
|
||||||
div+='<br>create new person NOT YET'
|
div+='<input type="hidden" id="refimg_data" name="refimg_data" value=""></input>'
|
||||||
|
div+=`
|
||||||
|
<div class="row col-12">
|
||||||
|
<label class="col-3" for="tag">Tag (searchable name):</label>
|
||||||
|
<input class="form-control col" id="tag" name="tag" required="" type="text" value="">
|
||||||
|
</div>
|
||||||
|
<div class="row col-12">
|
||||||
|
<label class="col-3" for="firstname">FirstName(s):</label>
|
||||||
|
<input class="form-control col" id="firstname" name="firstname" required="" type="text" value="">
|
||||||
|
</div>
|
||||||
|
<div class="row col-12">
|
||||||
|
<label class="col-3" for="surname">Surname:</label>
|
||||||
|
<input class="form-control col" id="surname" name="surname" required="" type="text" value="">
|
||||||
|
</div>
|
||||||
|
<div class="row col-12">
|
||||||
|
`
|
||||||
|
div+='<button class="btn btn-primary offset-3 col-2" type="button"'
|
||||||
|
div+='onClick="CreatePersonAndRefimg(\''+key+'\')">Save</button>'
|
||||||
}
|
}
|
||||||
if ( key == 'no_match_new_refimg' )
|
if ( key == 'no_match_new_refimg' )
|
||||||
{
|
{
|
||||||
|
|||||||
53
person.py
53
person.py
@@ -97,7 +97,7 @@ class PersonForm(FlaskForm):
|
|||||||
def AddRefimgToPerson( filename, person ):
|
def AddRefimgToPerson( filename, person ):
|
||||||
refimg = Refimg( fname=os.path.basename( filename ) )
|
refimg = Refimg( fname=os.path.basename( filename ) )
|
||||||
try:
|
try:
|
||||||
#False == dont autorotate, its not needed on this image
|
#False == dont autorotate, its not needed on this image
|
||||||
refimg.thumbnail, refimg.orig_w, refimg.orig_h = GenThumb( filename, False )
|
refimg.thumbnail, refimg.orig_w, refimg.orig_h = GenThumb( filename, False )
|
||||||
settings = Settings.query.first()
|
settings = Settings.query.first()
|
||||||
model=AIModel.query.get(settings.default_refimg_model)
|
model=AIModel.query.get(settings.default_refimg_model)
|
||||||
@@ -120,6 +120,24 @@ def AddRefimgToPerson( filename, person ):
|
|||||||
st.SetMessage( f"<b>Failed to modify Refimg:</b> {e}", "danger" )
|
st.SetMessage( f"<b>Failed to modify Refimg:</b> {e}", "danger" )
|
||||||
return
|
return
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# TempRefimgFile: helper function that takes data POST'd (from dialog box to
|
||||||
|
# add face to new/existing person). Converts data into a jpg file to be used by
|
||||||
|
# wrapper funcs to AI / refimg <-> person. filename will be <tag>.jpg
|
||||||
|
################################################################################
|
||||||
|
def TempRefimgFile( data, tag ):
|
||||||
|
# undo the munging sending via http has done
|
||||||
|
data=data.replace(' ', '+' )
|
||||||
|
|
||||||
|
# convert b64 encoded to a temp file to process...
|
||||||
|
bytes_decoded = base64.b64decode(data)
|
||||||
|
img = Image.open(BytesIO(bytes_decoded))
|
||||||
|
out_jpg = img.convert("RGB")
|
||||||
|
# save file to /tmp/<tag>.jpg
|
||||||
|
fname="/tmp/" + tag + ".jpg"
|
||||||
|
out_jpg.save(fname)
|
||||||
|
return fname
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Routes for person data
|
# Routes for person data
|
||||||
#
|
#
|
||||||
@@ -163,6 +181,18 @@ def new_person():
|
|||||||
else:
|
else:
|
||||||
return render_template("person.html", person=None, form=form, page_title=page_title )
|
return render_template("person.html", person=None, form=form, page_title=page_title )
|
||||||
|
|
||||||
|
@app.route("/match_with_create_person", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
def match_with_create_person():
|
||||||
|
p = Person( tag=request.form["tag"], surname=request.form["surname"], firstname=request.form["firstname"] )
|
||||||
|
# add this fname (of temp refimg) to person
|
||||||
|
fname=TempRefimgFile( request.form['refimg_data'], p.tag )
|
||||||
|
AddRefimgToPerson( fname, p )
|
||||||
|
resp={}
|
||||||
|
resp['who']=p.tag
|
||||||
|
resp['distance']='0.0'
|
||||||
|
return resp
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# /person/<id> -> GET/POST(save or delete) -> shows/edits/delets a single person
|
# /person/<id> -> GET/POST(save or delete) -> shows/edits/delets a single person
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -266,7 +296,6 @@ def find_persons(who):
|
|||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# /add_refimg_to_person/ -> POST
|
# /add_refimg_to_person/ -> POST
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -277,28 +306,10 @@ def add_refimg_to_person():
|
|||||||
f = Face.query.get( request.form['face_id'] )
|
f = Face.query.get( request.form['face_id'] )
|
||||||
p = Person.query.get( request.form['person_id'] )
|
p = Person.query.get( request.form['person_id'] )
|
||||||
|
|
||||||
file_eid = request.form['file_eid']
|
|
||||||
refimg_data = request.form['refimg_data']
|
|
||||||
|
|
||||||
# undo the munging sending via http has done
|
|
||||||
refimg_data=refimg_data.replace(' ', '+' )
|
|
||||||
|
|
||||||
print( refimg_data )
|
|
||||||
|
|
||||||
# convert b64 encoded to a temp file to process...
|
|
||||||
bytes_decoded = base64.b64decode(refimg_data)
|
|
||||||
img = Image.open(BytesIO(bytes_decoded))
|
|
||||||
out_jpg = img.convert("RGB")
|
|
||||||
# save file to /tmp/<p.tag>
|
|
||||||
fname="/tmp/" + p.tag + '.jpg'
|
|
||||||
out_jpg.save(fname)
|
|
||||||
|
|
||||||
# add this fname (of temp refimg) to person
|
# add this fname (of temp refimg) to person
|
||||||
|
fname=TempRefimgFile( request.form['refimg_data'], p.tag )
|
||||||
AddRefimgToPerson( fname, p )
|
AddRefimgToPerson( fname, p )
|
||||||
|
|
||||||
# DDP:
|
|
||||||
# need to create a new job to re-do AI now we have a new refimg in the mix
|
|
||||||
|
|
||||||
resp['who']=p.tag
|
resp['who']=p.tag
|
||||||
resp['distance']='0.0'
|
resp['distance']='0.0'
|
||||||
return resp
|
return resp
|
||||||
|
|||||||
Reference in New Issue
Block a user