-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatacollect.py
More file actions
38 lines (26 loc) · 885 Bytes
/
datacollect.py
File metadata and controls
38 lines (26 loc) · 885 Bytes
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
import cv2
video = cv2.VideoCapture(0)
facedetect = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
if not video.isOpened():
print("Error: Could not open camera.")
exit()
id = input("Enter your ID")
count = 0
while True:
ret, frame = video.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = facedetect.detectMultiScale(gray, 1.3, 5)
if not ret:
print("Failed to capture frame")
break
for (x, y, w, h) in faces:
count += 1
cv2.imwrite('datasets/User.' + str(id) + '.' + str(count) + '.jpg', gray[y:y+h, x:x+w])
cv2.rectangle(frame, (x, y), (x+w, y+h), (50, 50, 225), 1)
cv2.imshow("Frame", frame)
k = cv2.waitKey(1)
if count > 500:
break
video.release()
cv2.destroyAllWindows()
print("Dataset Collection Done.............")