-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasetCreation.py
57 lines (47 loc) · 1.32 KB
/
datasetCreation.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
import imutils
import time
import cv2
import csv
import os
import preprocessingEmbeddings as pE
import trainingFaceML as tF
cascade = 'haarcascade_frontalface_default.xml'
detector = cv2.CascadeClassifier(cascade)
Name = str(input("Enter your Name : "))
Roll_Number = int(input("Enter your Roll_Number : "))
dataset = 'dataset'
sub_data = Name
path = os.path.join(dataset, sub_data)
if not os.path.isdir(path):
os.mkdir(path)
print(sub_data)
info = [str(Name), str(Roll_Number)]
with open('student.csv', 'a') as csvFile:
write = csv.writer(csvFile)
write.writerow(info)
csvFile.close()
print("Starting video stream...")
cam = cv2.VideoCapture(0)
time.sleep(2.0)
total = 0
while total < 50:
print(total)
_, frame = cam.read()
img = imutils.resize(frame, width=400)
rects = detector.detectMultiScale(
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), scaleFactor=1.1,
minNeighbors=5, minSize=(30, 30))
for (x, y, w, h) in rects:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
p = os.path.sep.join([path, "{}.png".format(
str(total).zfill(5))])
cv2.imwrite(p, img)
total += 1
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cam.release()
cv2.destroyAllWindows()
pE.embeddings()
tF.training()