-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict_real_time.py
84 lines (55 loc) · 1.71 KB
/
predict_real_time.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
###########################################################################
# FaceEmoji/test_face_cropping.py
# This file tests the face cropping functionality using open CV
###########################################################################
import os
import numpy as np
from matplotlib import pyplot as plt
import cv2 as cv
from PIL import Image
import Lib.utils as utils
def main():
# initializing camera
cam = cv.VideoCapture(0)
cv.namedWindow("Test Face Cropping")
# initalizng face cropper
face_crop = utils.FaceCrop()
# main loop
while True:
# taking image and processing it
ret, frame = cam.read()
faces = face_crop.crop_face_from_image(frame)
# getting faces
face_crop.get_faces(frame, faces)
# Draw rectangle around the faces
for (x, y, w, h) in faces:
cv.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2)
cv.imshow("Test Face Cropping", frame)
if not ret:
break
k = cv.waitKey(1)
# when ESC pressed, finish running
if k%256 == 27:
print("Escape pressed, closing...")
break
# finishing camera
cam.release()
cv.destroyAllWindows()
def main2():
path = os.path.join(os.getcwd(),"Data","sunglasses","1 (13).png")
img = np.array(Image.open(path))
plt.figure()
plt.imshow(img)
#initalizng face cropper
face_crop = utils.FaceCrop(reshape=False)
# getting faces coords
faces = face_crop.crop_face_from_image(img)
# getting faces
face_imgs = face_crop.get_faces(img, faces)
plt.figure()
plt.imshow(face_imgs[0])
plt.show()
if __name__ == "__main__":
main()
#main2()
#