better sysout from facematch parav

This commit is contained in:
Ox 2023-10-12 13:03:08 -03:00
parent c6af086495
commit 1df77fa652
2 changed files with 34 additions and 11 deletions

View File

@ -15,6 +15,8 @@ import paravision.recognition.utils as pru
class Facematch(object): class Facematch(object):
errstr = ""
def init(self): def init(self):
print("@@@ initialising paravision") print("@@@ initialising paravision")
try: try:
@ -62,27 +64,36 @@ class Facematch(object):
print("## loading images", dev1, dev2) print("## loading images", dev1, dev2)
self.dev1 = dev1 self.dev1 = dev1
self.dev2 = dev2 self.dev2 = dev2
errstr = ""
try: try:
# Load images # Load images
errstr = "id image load"
self.id_image = pru.load_image(id_image_filepath) self.id_image = pru.load_image(id_image_filepath)
errstr = "client photo load"
self.photo_image = pru.load_image(photo_image_filepath) self.photo_image = pru.load_image(photo_image_filepath)
print("++++++++++++++++ ",self.id_image) #print("++++++++++++++++ ",self.id_image)
return True return True
except Exception as e: except Exception as e:
print("uk oh loading failed ", e) print("uk oh loading failed ", e)
return None return False
def get_faces(self): def get_faces(self):
print("# get faces...")
errstr = ""
try: try:
# Get all faces from images with qualities, landmarks, and embeddings # Get all faces from images with qualities, landmarks, and embeddings
errstr = "getting faces"
self.inference_result = self.sdk.get_faces([self.id_image, self.photo_image], qualities=True, landmarks=True, embeddings=True) self.inference_result = self.sdk.get_faces([self.id_image, self.photo_image], qualities=True, landmarks=True, embeddings=True)
self.image_inference_result = self.inference_result.image_inferences self.image_inference_result = self.inference_result.image_inferences
if len(self.image_inference_result)==0: if len(self.image_inference_result)==0:
return "no inferences found" return "no inferences found"
# Get most prominent face # Get most prominent face
print("most prominent...")
errstr = "getting most prominent id face"
self.id_face = self.image_inference_result[0].most_prominent_face_index() self.id_face = self.image_inference_result[0].most_prominent_face_index()
errstr = "getting most prominent id face"
self.photo_face = self.image_inference_result[1].most_prominent_face_index() self.photo_face = self.image_inference_result[1].most_prominent_face_index()
if self.id_face<0: if self.id_face<0:
return "no id face found" return "no id face found"
@ -90,23 +101,27 @@ class Facematch(object):
return "no live face found" return "no live face found"
# Get numerical representation of faces (required for face match) # Get numerical representation of faces (required for face match)
print("digesting...")
errstr = "getting numericals"
if (len(self.image_inference_result)<2): if (len(self.image_inference_result)<2):
return "ID or human face could not be recognised" return "ID or human face could not be recognised"
self.id_emb = self.image_inference_result[0].faces[self.id_face].embedding self.id_emb = self.image_inference_result[0].faces[self.id_face].embedding
self.photo_emb = self.image_inference_result[1].faces[self.photo_face].embedding self.photo_emb = self.image_inference_result[1].faces[self.photo_face].embedding
except Exception as ex: except Exception as ex:
return "image processing exception "+str(ex) errstr = "image processing exception "+str(ex)
return False
return None return True
# return " id=%d photo=%d result=%d " % (self.id_face, self.photo_face, len(self.image_inference_result)) # return " id=%d photo=%d result=%d " % (self.id_face, self.photo_face, len(self.image_inference_result))
def compute_scores(self): def compute_scores(self):
print("## compute scores...")
try: try:
# Get image quality scores (how 'good' a face is) # Get image quality scores (how 'good' a face is)
errstr = "getting image quality"
self.id_qual = self.image_inference_result[0].faces[self.id_face].quality self.id_qual = self.image_inference_result[0].faces[self.id_face].quality
self.photo_qual = self.image_inference_result[1].faces[self.photo_face].quality self.photo_qual = self.image_inference_result[1].faces[self.photo_face].quality
@ -114,6 +129,7 @@ class Facematch(object):
self.photo_qual = round(self.photo_qual, 3) self.photo_qual = round(self.photo_qual, 3)
# Get face match score # Get face match score
errstr = "scoring"
self.match_score = self.sdk.get_match_score(self.id_emb, self.photo_emb) self.match_score = self.sdk.get_match_score(self.id_emb, self.photo_emb)
# Create .json # Create .json
@ -137,7 +153,11 @@ class Facematch(object):
#print(response.read()) #print(response.read())
except Exception as ex: except Exception as ex:
return str(ex) errstr = str(ex)
return False
return True
def get_scores(self): def get_scores(self):

View File

@ -179,14 +179,17 @@ class yoloserv(object):
if self.conf["emulate_facematch"]: if self.conf["emulate_facematch"]:
return '{ "status":0, "remark":"OK", "data":{} }' return '{ "status":0, "remark":"OK", "data":{} }'
self.facematcher.load(dev1, dev2, img1, img2) status = self.facematcher.load(dev1, dev2, img1, img2)
if not status:
return '{ "status":777242, "remark":"face loading failed", "guilty_param":"facematch", "guilty_value":"%s" }' % (self.facematcher.errstr)
status = self.facematcher.get_faces() status = self.facematcher.get_faces()
if status is not None: if not status:
return '{ "status":777242, "remark":"face matching failed", "guilty_param":"facematch", "guilty_value":"%s" }' % (status) return '{ "status":777245, "remark":"face finding failed", "guilty_param":"facematch", "guilty_value":"%s" }' % (self.facematcher.errstr)
status = self.facematcher.compute_scores() status = self.facematcher.compute_scores()
if status is not None: if not status:
return '{ "status":777243, "remark":"face scoring failed", "guilty_param":"facematch", "guilty_value":"%s" }' % (status) return '{ "status":777243, "remark":"face scoring failed", "guilty_param":"facematch", "guilty_value":"%s" }' % (self.facematch.errstr)
jsonstr = self.facematcher.get_scores() jsonstr = self.facematcher.get_scores()
return '{ "status":0, "remark":"OK", "data":%s }' % (jsonstr) return '{ "status":0, "remark":"OK", "data":%s }' % (jsonstr)