File size: 1,868 Bytes
9d3162f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from deepface import DeepFace

class CaesarDeepFace:
    """
    https://github.com/serengil/deepface
    """
    def __init__(self) -> None:
        self.metrics = ["cosine", "euclidean", "euclidean_l2"]
        self.models = ["VGG-Face", "Facenet", "Facenet512", "OpenFace", "DeepFace", "DeepID", "ArcFace", "Dlib", "SFace"]
        self.backends = [
            'opencv', 
            'ssd', 
            'dlib', 
            'mtcnn', 
            'retinaface', 
            'mediapipe'
            ]
    def face_authentication(self,filename1="img1.jpg",filename2="img2.jpg"):
        #face verification
        # Value Error
        try:
            result = DeepFace.verify(img1_path =filename1 , 
                    img2_path = filename2, 
                    distance_metric = self.metrics[0],
                    model_name = self.models[0],
                    detector_backend = self.backends[0]
            )
            return result
        except ValueError as vex:
            return {"message":"Face wasn't detected","error":f"{type(vex)},{vex}"}
    def face_recognition(self,filename,db_path="C:/workspace/my_db"):
        dfs = DeepFace.find(img_path =filename, 
          db_path = db_path, 
          distance_metric = self.metrics[2])
        return dfs
    def face_analyze(self,filename="img1.jpg"):
        objs = DeepFace.analyze(img_path = filename, 
        actions = ['age', 'gender', 'race', 'emotion'])
        return objs
    def face_embeddigns(self,filename):
        embedding_objs = DeepFace.represent(img_path = filename)
        return embedding_objs
    def face_streaming(self,db_path="C:/User/Sefik/Desktop/database"):
        DeepFace.stream(db_path = db_path)
        

if __name__ == "__main__":
    caesardeepface = CaesarDeepFace()
    result =  caesardeepface.face_authentication(filename2="img3.jpg")
    print(result)