From 201133f7dac541fb5a6f52d727b994cc8799a6ee Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 12 Sep 2023 08:38:22 -0300 Subject: [PATCH] some refactoring ahead of ukdi divorce proceedings... --- src/paravisionx.py | 135 --------------------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 src/paravisionx.py diff --git a/src/paravisionx.py b/src/paravisionx.py deleted file mode 100644 index b8db4a8d7..000000000 --- a/src/paravisionx.py +++ /dev/null @@ -1,135 +0,0 @@ - -from paravision.recognition.exceptions import ParavisionException -from paravision.recognition.engine import Engine -from paravision.recognition.sdk import SDK -from openvino.inference_engine import Engineq - -#from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace, DeepID - - -class Paravisionx(object): - - def init(self): - print("@@@ initialising paravision") - - try: - self.sdk = SDK(engine=Engine.AUTO) - except ParavisionException: - pass - - def read(self, imgpath): - if not os.path.exists(imgpath): - print("File not found ",imgpath) - return False - self.imgpath = imgpath - self.image = pru.load_image(imgpath) - print(self.image) - return True - - def process(self): - # Get all faces metadata - print("Finding faces in %s" %(self.imgpath)) - faces = self.sdk.get_faces([self.image], qualities=True, landmarks=True, embeddings=True) - print("Getting metadata") - inferences = faces.image_inferences - print("Getting best face") - ix = inferences[0].most_prominent_face_index() - print("Getting a mathematical mode of that best face") - self.model = inferences[0].faces[ix].embedding - print("Getting image quality scores..") - self.score = round(1000*inferences[0].faces[ix].quality) - print("Score was %d" %(self.score)) - return self.score - - def compare(self,other): - # Get face match score - return self.sdk.get_match_score(self.model, other.model) - - - #mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - - - def load(self, dev1, dev2, id_image_filepath, photo_image_filepath): - self.dev1 = dev1 - self.dev2 = dev2 - try: - # Load images - self.id_image = load_image(id_image_filepath) - self.photo_image = load_image(photo_image_filepath) - print("++++++++++++++++ ",self.id_image) - return True - except: - return None - - - def get_faces(self): - try: - # Get all faces from images with qualities, landmarks, and embeddings - 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 - if len(self.image_inference_result)==0: - return "no inferences found" - - # Get most prominent face - self.id_face = self.image_inference_result[0].most_prominent_face_index() - self.photo_face = self.image_inference_result[1].most_prominent_face_index() - if self.id_face<0: - return "no id face found" - if self.photo_face<0: - return "no live face found" - - # Get numerical representation of faces (required for face match) - 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: - 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): - try: - # Get image quality scores (how 'good' a face is) - 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.id_qual = round(self.id_qual, 3) - self.photo_qual = round(self.photo_qual, 3) - - # Get face match score - self.match_score = self.sdk.get_match_score(self.id_emb, self.photo_emb) - - # Create .json - self.face_match_json = {"device1":self.dev1, - "device2":self.dev2, - "passmark":500, - "device1_qual":self.id_qual, - "device2_qual":self.photo_qual, - "match_score":self.match_score} - - #return json.dumps(self.face_match_json) - - #print(self.face_match_json) - - # Send to core - #url = "%s/notify/%s/%s" % (self.conf["core"], self.conf["identity"], face_match_json) - #url = url.replace(" ", "%20") # Remove spaces - #buf = [] - #req = urllib.request.Request( url ) - #with urllib.request.urlopen(req) as response: - #print(response.read()) - - except Exception as ex: - return str(ex) - - - def get_scores(self): - return json.dumps(self.face_match_json) -