-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
57 lines (52 loc) · 2.49 KB
/
app.py
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
51
52
53
54
55
56
57
import warnings
warnings.filterwarnings("ignore")
import cv2
from time import time
from matplotlib import pyplot as plt
from face_detection.detections import Face_Detection
from face_alignment.simple_alignment.align import Simple_Alignment
from face_recognition.recognitions_models.openface.OpenFace import OpenFace
if __name__ == "__main__":
print("Face Detection Model")
image_path = r"./test_images/3.png"
image = cv2.imread(image_path)
image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
# create opencv face detection instance
face_detection_models = ["opencv","yolo","retinaface_v1","retinaface_v2","mtcnn"]
for idx, face_detector in enumerate(face_detection_models):
image_path = r"./test_images/1.png"
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
tic = time()
face_detection = Face_Detection(model_name=face_detector)
return_crops = True
return_keypoints = True if face_detector != "opencv" else False
draw_bbox = True
draw_keypoint = True if face_detector != "opencv" else False
main_image, bboxes, keypoints, crops = face_detection.detect(image=image,
return_crops=return_crops,
return_keypoints=return_keypoints,
draw_bbox=draw_bbox,
draw_keypoint=draw_keypoint)
toc = time()
plt.subplot(1, len(face_detection_models), idx+1)
plt.title(f"Detector : {face_detector} , time:{toc-tic:.4} S")
plt.imshow(main_image, cmap='gray')
plt.show()
aligned_faces = []
if face_detection_models != "opencv":
face_alignment = Simple_Alignment()
for face , keypoint in zip(crops,keypoints):
main_face , aligned_face = face_alignment.align(face,keypoint)
aligned_faces.append(aligned_face)
plt.subplot(1,2,1)
plt.imshow(face,cmap='gray')
plt.subplot(1,2,2)
plt.imshow(aligned_face,cmap='gray')
plt.show()
if len(aligned_faces) > 0 :
# face recognition model
openface = OpenFace()
for face in aligned_faces:
embedding = openface.predict(image=face)
print(embedding.shape)