refimgs now contain face, orig_w, orig_h and face_locns. This is done via json.* to allow arrays to be saved/loaded back into face_locn - not useful for refimg as there has to be only 1, but tested for images where there will be many faces. This commit has a fair few changes. So overall, no more refimg menus/creation. You now create a person (the add button is hidden until you save), when you save you go back to the person you created rather than the list of persons. From there you can click add ref img, and it will create a thumbnail, and draw a green box around the face locations based on the data. Persons can have many refimgs, and they will all work the same, be formatted prettily no matter how many you have. Each refimg "tab" not only has the thumbnail, but also a red X click to delete button that will remove all refimg data and connection to the person table too. This all works/is tested.
This commit is contained in:
15
person.py
15
person.py
@@ -10,6 +10,7 @@ from werkzeug import secure_filename
|
||||
from shared import GenFace, GenThumb
|
||||
from face import FaceRefimgLink
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
# pylint: disable=no-member
|
||||
@@ -21,6 +22,9 @@ class Refimg(db.Model):
|
||||
id = db.Column(db.Integer, db.Sequence('refimg_id_seq'), primary_key=True )
|
||||
fname = db.Column(db.String(256), unique=True, nullable=False)
|
||||
face = db.Column(db.LargeBinary, unique=True, nullable=False)
|
||||
orig_w = db.Column(db.Integer)
|
||||
orig_h = db.Column(db.Integer)
|
||||
face_locn = db.Column(db.String)
|
||||
thumbnail = db.Column(db.String, unique=True, nullable=False)
|
||||
created_on = db.Column(db.Float)
|
||||
|
||||
@@ -41,7 +45,7 @@ class Person(db.Model):
|
||||
tag = db.Column(db.String(48), unique=False, nullable=False)
|
||||
surname = db.Column(db.String(48), unique=False, nullable=False)
|
||||
firstname = db.Column(db.String(48), unique=False, nullable=False)
|
||||
refimg = db.relationship('Refimg', secondary=PersonRefimgLink.__table__)
|
||||
refimg = db.relationship('Refimg', secondary=PersonRefimgLink.__table__, order_by=Refimg.id)
|
||||
|
||||
def __repr__(self):
|
||||
return "<tag: {}, firstname: {}, surname: {}, refimg: {}>".format(self.tag,self.firstname, self.surname, self.refimg)
|
||||
@@ -94,7 +98,7 @@ def new_person():
|
||||
db.session.add(person)
|
||||
db.session.commit()
|
||||
st.SetMessage( "Created new Person ({})".format(person.tag) )
|
||||
return redirect( '/persons' )
|
||||
return redirect( f'/person/{person.id}' )
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( "<b>Failed to add Person:</b> {}".format(e.orig) )
|
||||
@@ -141,6 +145,8 @@ def person(id):
|
||||
return render_template("person.html", form=form, page_title=page_title)
|
||||
else:
|
||||
person = Person.query.get(id)
|
||||
for r in person.refimg:
|
||||
r.face_locn=json.loads(r.face_locn)
|
||||
form = PersonForm(request.values, obj=person)
|
||||
return render_template("person.html", person=person, form=form, page_title = page_title)
|
||||
|
||||
@@ -164,8 +170,9 @@ def add_refimg():
|
||||
|
||||
fname = f"/tmp/{fname}"
|
||||
f.save( fname )
|
||||
refimg.thumbnail = GenThumb( fname )
|
||||
refimg.face = GenFace( fname )
|
||||
refimg.thumbnail, refimg.orig_w, refimg.orig_h = GenThumb( fname )
|
||||
refimg.face, face_locn = GenFace( fname )
|
||||
refimg.face_locn = json.dumps(face_locn)
|
||||
os.remove(fname)
|
||||
person.refimg.append(refimg)
|
||||
db.session.add(person)
|
||||
|
||||
Reference in New Issue
Block a user