-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealTimeAddToDatabase.py
More file actions
52 lines (43 loc) · 1.53 KB
/
RealTimeAddToDatabase.py
File metadata and controls
52 lines (43 loc) · 1.53 KB
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
from TrainingandTest import *
from Preprocessing import *
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
save_path = "C:/Users/lenovo system/PycharmProjects/FaceRecognition/CK+48"
def mouse_click(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
images.append(gray)
print("Added")
if __name__ == '__main__':
images = []
webcam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cv2.namedWindow('hey')
cv2.setMouseCallback('hey', mouse_click)
while True:
ret, frame = webcam.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces_ = face_cascade.detectMultiScale(gray)
for (x, y, w, h) in faces_:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
cv2.imshow('hey', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
webcam.release()
histo = []
name = input()
img_count = 0
for img in images:
img_count += 1
filename = name + '_' + str(img_count) + '.jpg'
cv2.imwrite(os.path.join(save_path, filename), img)
roi_face = preprocess(img)
if roi_face is None:
print("One pic down")
continue
LBP_image = extended_lbp(roi_face)
hist = plot_hist(LBP_image)
histo.append(hist)
if hist is not None:
with open('labeldata.csv', 'a') as f:
f.write(name + '\n')
f = open('histodata.csv', 'ab')
np.savetxt(f, histo, fmt='%1.1f', delimiter=',')