-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatacollect.py
42 lines (31 loc) · 877 Bytes
/
datacollect.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
import cv2
import os
video=cv2.VideoCapture(0)
facedetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
count=0
# Copyright 2023 Pabitra Banerjee
nameID=str(input("Enter Your Name: ")).lower()
path='images/'+nameID
isExist = os.path.exists(path)
if isExist:
print("Name Already Taken")
nameID=str(input("Enter Your Name Again: "))
else:
os.makedirs(path)
# Copyright 2023 Pabitra Banerjee
while True:
ret,frame=video.read()
faces=facedetect.detectMultiScale(frame,1.3, 5)
for x,y,w,h in faces:
count=count+1
name='./images/'+nameID+'/'+ str(count) + '.jpg'
print("Creating Images........." +name)
cv2.imwrite(name, frame[y:y+h,x:x+w])
cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,0), 3)
cv2.imshow("WindowFrame", frame)
cv2.waitKey(1)
if count>500:
break
video.release()
cv2.destroyAllWindows()
# Copyright 2023 Pabitra Banerjee