now can create a new person and refimg from viewer - all works
This commit is contained in:
53
person.py
53
person.py
@@ -97,7 +97,7 @@ class PersonForm(FlaskForm):
|
||||
def AddRefimgToPerson( filename, person ):
|
||||
refimg = Refimg( fname=os.path.basename( filename ) )
|
||||
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 )
|
||||
settings = Settings.query.first()
|
||||
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" )
|
||||
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
|
||||
#
|
||||
@@ -163,6 +181,18 @@ def new_person():
|
||||
else:
|
||||
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
|
||||
################################################################################
|
||||
@@ -266,7 +296,6 @@ def find_persons(who):
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
# /add_refimg_to_person/ -> POST
|
||||
################################################################################
|
||||
@@ -277,28 +306,10 @@ def add_refimg_to_person():
|
||||
f = Face.query.get( request.form['face_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
|
||||
fname=TempRefimgFile( request.form['refimg_data'], p.tag )
|
||||
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['distance']='0.0'
|
||||
return resp
|
||||
|
||||
Reference in New Issue
Block a user