-
Notifications
You must be signed in to change notification settings - Fork 13
/
register.py
37 lines (29 loc) · 1.06 KB
/
register.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
# register.py
import cv2
from facerec import detect_faces
def registerCriminal(img, path, img_num):
size = 2
(im_width, im_height) = (112, 92)
file_num = 2*img_num - 1
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detect_faces(gray)
if(len(faces) > 0):
# Taking the largest face detected
faces = sorted(faces, key=lambda x: x[3], reverse=True) # sort based on height of image
face_i = faces[0]
(x, y, w, h) = [v * size for v in face_i]
face = gray[y:y + h, x:x + w]
face = cv2.resize(face, (im_width, im_height))
print("Saving training sample " + str(img_num)+".1")
# Save image file
cv2.imwrite('%s/%s.png' % (path, file_num), face)
file_num += 1
# Save flipped image
print("Saving training sample " + str(img_num)+".2")
face = cv2.flip(face, 1, 0)
cv2.imwrite('%s/%s.png' % (path, file_num), face)
else:
# No face present
print("img %d : Face is not present" % (img_num))
return img_num
return None