tried to make it faster
This commit is contained in:
parent
1df77fa652
commit
084d470005
@ -15,8 +15,6 @@ import paravision.recognition.utils as pru
|
||||
|
||||
class Facematch(object):
|
||||
|
||||
errstr = ""
|
||||
|
||||
def init(self):
|
||||
print("@@@ initialising paravision")
|
||||
try:
|
||||
@ -64,36 +62,31 @@ class Facematch(object):
|
||||
print("## loading images", dev1, dev2)
|
||||
self.dev1 = dev1
|
||||
self.dev2 = dev2
|
||||
errstr = ""
|
||||
try:
|
||||
# Load images
|
||||
errstr = "id image load"
|
||||
self.id_image = pru.load_image(id_image_filepath)
|
||||
errstr = "client photo load"
|
||||
self.photo_image = pru.load_image(photo_image_filepath)
|
||||
#print("++++++++++++++++ ",self.id_image)
|
||||
return True
|
||||
except Exception as e:
|
||||
print("uk oh loading failed ", e)
|
||||
return False
|
||||
return "id image loading failed ", e
|
||||
try:
|
||||
self.photo_image = pru.load_image(photo_image_filepath)
|
||||
except Exception as e:
|
||||
return "client image loading failed ", e
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def get_faces(self):
|
||||
print("# get faces...")
|
||||
errstr = ""
|
||||
try:
|
||||
# Get all faces from images with qualities, landmarks, and embeddings
|
||||
errstr = "getting faces"
|
||||
print("Finding faces...")
|
||||
self.inference_result = self.sdk.get_faces([self.id_image, self.photo_image], qualities=True, landmarks=True, embeddings=True)
|
||||
print("Inferences...")
|
||||
self.image_inference_result = self.inference_result.image_inferences
|
||||
if len(self.image_inference_result)==0:
|
||||
return "no inferences found"
|
||||
|
||||
# Get most prominent face
|
||||
print("most prominent...")
|
||||
errstr = "getting most prominent id face"
|
||||
print("Most prominent...")
|
||||
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()
|
||||
if self.id_face<0:
|
||||
return "no id face found"
|
||||
@ -101,27 +94,24 @@ class Facematch(object):
|
||||
return "no live face found"
|
||||
|
||||
# Get numerical representation of faces (required for face match)
|
||||
print("digesting...")
|
||||
errstr = "getting numericals"
|
||||
print("stats...")
|
||||
if (len(self.image_inference_result)<2):
|
||||
return "ID or human face could not be recognised"
|
||||
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
|
||||
|
||||
except Exception as ex:
|
||||
errstr = "image processing exception "+str(ex)
|
||||
return False
|
||||
return True
|
||||
return "image processing exception "+str(ex)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
# return " id=%d photo=%d result=%d " % (self.id_face, self.photo_face, len(self.image_inference_result))
|
||||
|
||||
|
||||
def compute_scores(self):
|
||||
print("## compute scores...")
|
||||
try:
|
||||
# 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.photo_qual = self.image_inference_result[1].faces[self.photo_face].quality
|
||||
|
||||
@ -129,7 +119,6 @@ class Facematch(object):
|
||||
self.photo_qual = round(self.photo_qual, 3)
|
||||
|
||||
# Get face match score
|
||||
errstr = "scoring"
|
||||
self.match_score = self.sdk.get_match_score(self.id_emb, self.photo_emb)
|
||||
|
||||
# Create .json
|
||||
@ -153,11 +142,7 @@ class Facematch(object):
|
||||
#print(response.read())
|
||||
|
||||
except Exception as ex:
|
||||
errstr = str(ex)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
return str(ex)
|
||||
|
||||
|
||||
def get_scores(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user