-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDATA_COLLECT.py
55 lines (38 loc) · 1.27 KB
/
DATA_COLLECT.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
import os
import cv2
from libs import FaceModel
from libs.utils.utils import show_bboxes
from libs.utils.align import warp_and_crop_face, get_reference_facial_points, get_aligned_faces
from libs.mtcnn.mtcnn import MTCNN
mtcnn = MTCNN()
cap = cv2.VideoCapture(0)
if __name__ == "__main__":
who = input("Enter your Name: ")
directory = "FaceName" + "\\" + str(who)
if not os.path.exists(directory):
os.makedirs(directory)
else:
print("YOUR FACE IMAGES ALREADY EXISTS")
exit(0)
count = 0
img_count = 0
while True:
count += 1
img_count += 1
_,frame=cap.read()
frame = cv2.flip(frame, flipCode = 1 )
names = []
names.append(who)
landmarks, bboxs = mtcnn(frame)
faces = get_aligned_faces(frame, bboxs, landmarks)
frame = show_bboxes(frame , bboxs , landmarks , names)
for face in faces:
if count % 10 == 0:
cv2.imwrite( directory + "\\" + str(who) + "_" +str(count) + ".jpg", face)
cv2.imshow("FRAME",frame)
if img_count == 300:
exit(0)
key=cv2.waitKey(15)
if key==ord('q'):
break
cv2.destroyAllWindows()