-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinclude.py
63 lines (50 loc) · 1.45 KB
/
include.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
import csv
import cv2
import os
if not os.path.exists('./dataset'):
os.makedirs('./dataset')
name = input("enter your name")
roll = input("enter your id")
row = [name,roll,'A']
l =[]
for root ,dire,filenames in os.walk('dataset'):
for names in dire:
l.append(int(names))
folder = str(l[-1]+1)
os.makedirs(f'./dataset/{folder}')
def add(row):
with open('data.csv','a') as f:
writer = csv.writer(f,lineterminator='\n')
writer.writerow(row)
# with open('data.csv') as f:
# data = csv.reader(f)
# next(data)
# for names in data:
# if names[0] == name:
# print('already exist!!')
# break
# else:
# add(row)
# print('added')
# break
# print(names)
capture = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
framecount = 0
flag,image = capture.read()
while True:
flag,frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
framecount += 1
cv2.imwrite(f'dataset/{folder}/{name}.{roll}.{framecount}.jpg',frame)
print('frame no',framecount,' captured!')
cv2.rectangle(frame, (x,y), (x+w, y+h), (255,0,0), 2)
cv2.waitKey(100)
cv2.imshow('img',frame)
cv2.waitKey(1)
if framecount >200:
break
capture.release()
cv2.destroyAllWindows()