remove own copy of GenThumb, and use the one from shared.py. Also use zip() to merge face locations and encodings for AddFaceToFile()
This commit is contained in:
@@ -31,7 +31,7 @@ from sqlalchemy.orm import scoped_session
|
|||||||
|
|
||||||
### LOCAL FILE IMPORTS ###
|
### LOCAL FILE IMPORTS ###
|
||||||
|
|
||||||
from shared import DB_URL, PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT, THUMBSIZE, SymlinkName
|
from shared import DB_URL, PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT, THUMBSIZE, SymlinkName, GenThumb
|
||||||
from datetime import datetime, timedelta, date
|
from datetime import datetime, timedelta, date
|
||||||
|
|
||||||
### PYTHON LIB IMPORTS ###
|
### PYTHON LIB IMPORTS ###
|
||||||
@@ -52,6 +52,7 @@ import io
|
|||||||
import face_recognition
|
import face_recognition
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
# this is required to handle the duplicate processing code
|
# this is required to handle the duplicate processing code
|
||||||
@@ -230,6 +231,7 @@ class Face(Base):
|
|||||||
__tablename__ = "face"
|
__tablename__ = "face"
|
||||||
id = Column(Integer, Sequence('face_id_seq'), primary_key=True )
|
id = Column(Integer, Sequence('face_id_seq'), primary_key=True )
|
||||||
face = Column( LargeBinary )
|
face = Column( LargeBinary )
|
||||||
|
locn = Column(String)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<id: {self.id}, face={self.face}"
|
return f"<id: {self.id}, face={self.face}"
|
||||||
@@ -1042,7 +1044,7 @@ def JobRotateImage(job):
|
|||||||
AddLogForJob(job, f"INFO: Rotating {e.FullPathOnFS()} by {amt} degrees" )
|
AddLogForJob(job, f"INFO: Rotating {e.FullPathOnFS()} by {amt} degrees" )
|
||||||
out = im.rotate(int(amt), expand=True)
|
out = im.rotate(int(amt), expand=True)
|
||||||
out.save( e.FullPathOnFS() )
|
out.save( e.FullPathOnFS() )
|
||||||
e.file_details.thumbnail = GenThumb( e.FullPathOnFS() )
|
e.file_details.thumbnail, _ , _ = GenThumb( e.FullPathOnFS() )
|
||||||
session.add(e)
|
session.add(e)
|
||||||
FinishJob(job, "Finished Processesing image rotation/flip")
|
FinishJob(job, "Finished Processesing image rotation/flip")
|
||||||
return
|
return
|
||||||
@@ -1183,27 +1185,10 @@ def isImage(file):
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def GenThumb(file):
|
|
||||||
try:
|
|
||||||
im_orig = Image.open(file)
|
|
||||||
im = ImageOps.exif_transpose(im_orig)
|
|
||||||
bands = im.getbands()
|
|
||||||
if 'A' in bands:
|
|
||||||
im = im.convert('RGB')
|
|
||||||
im.thumbnail((THUMBSIZE,THUMBSIZE))
|
|
||||||
img_bytearray = io.BytesIO()
|
|
||||||
im.save(img_bytearray, format='JPEG')
|
|
||||||
img_bytearray = img_bytearray.getvalue()
|
|
||||||
thumbnail = base64.b64encode(img_bytearray)
|
|
||||||
thumbnail = str(thumbnail)[2:-1]
|
|
||||||
return thumbnail
|
|
||||||
except Exception as e:
|
|
||||||
AddLogForJob(job, f"WARNING: No EXIF TAF found for: {file} - error={e}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
def GenImageThumbnail(job, file):
|
def GenImageThumbnail(job, file):
|
||||||
ProcessFileForJob( job, "Generate Thumbnail from Image file: {}".format( file ), file )
|
ProcessFileForJob( job, "Generate Thumbnail from Image file: {}".format( file ), file )
|
||||||
return GenThumb(file)
|
thumb, _, _ = GenThumb(file)
|
||||||
|
return thumb
|
||||||
|
|
||||||
def GenVideoThumbnail(job, file):
|
def GenVideoThumbnail(job, file):
|
||||||
ProcessFileForJob( job, "Generate Thumbnail from Video file: {}".format( file ), file )
|
ProcessFileForJob( job, "Generate Thumbnail from Video file: {}".format( file ), file )
|
||||||
@@ -1418,8 +1403,8 @@ def InitialValidationChecks():
|
|||||||
FinishJob(job,"Finished Initial Validation Checks")
|
FinishJob(job,"Finished Initial Validation Checks")
|
||||||
return
|
return
|
||||||
|
|
||||||
def AddFaceToFile( face_data, file_eid ):
|
def AddFaceToFile( locn_data, face_data, file_eid ):
|
||||||
face = Face( face=face_data.tobytes() )
|
face = Face( face=face_data.tobytes(), locn=json.dumps(locn_data) )
|
||||||
session.add(face)
|
session.add(face)
|
||||||
session.commit()
|
session.commit()
|
||||||
ffl = FaceFileLink( face_id=face.id, file_eid=file_eid )
|
ffl = FaceFileLink( face_id=face.id, file_eid=file_eid )
|
||||||
@@ -1458,8 +1443,8 @@ def ScanFileForPerson( job, e, person_id, force=False ):
|
|||||||
im = face_recognition.load_image_file(e.FullPathOnFS())
|
im = face_recognition.load_image_file(e.FullPathOnFS())
|
||||||
face_locations = face_recognition.face_locations(im)
|
face_locations = face_recognition.face_locations(im)
|
||||||
unknown_encodings = face_recognition.face_encodings(im, known_face_locations=face_locations)
|
unknown_encodings = face_recognition.face_encodings(im, known_face_locations=face_locations)
|
||||||
for face in unknown_encodings:
|
for locn, face in zip( face_locations, unknown_encodings ):
|
||||||
AddFaceToFile( face, e.id )
|
AddFaceToFile( locn, face, e.id )
|
||||||
file_h.faces_created_on = time.time()
|
file_h.faces_created_on = time.time()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user