-
Notifications
You must be signed in to change notification settings - Fork 13
/
Capture_Image.py
79 lines (64 loc) · 2.26 KB
/
Capture_Image.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv
import re
import cv2
import os
#from main_gui import tkEmail, tkID, tkName
# counting the numbers
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
# Take image function
def takeImages(Id,name,email):
#Id = str(tkID)
#name = str(tkName)
#email = str(tkEmail)
print(Id,name,email)
regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
if(is_number(Id) and re.search(regex,email)):
cam = cv2.VideoCapture(0)
harcascadePath = "haarcascade_frontalface_default.xml"
detector = cv2.CascadeClassifier(harcascadePath)
sampleNum = 0
while(True):
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5, minSize=(30,30),flags = cv2.CASCADE_SCALE_IMAGE)
for(x,y,w,h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (10, 159, 255), 2)
#incrementing sample number
sampleNum = sampleNum+1
#saving the captured face in the dataset folder TrainingImage
cv2.imwrite("TrainingImage" + os.sep +name + "."+Id + '.' +
str(sampleNum) + ".jpg", gray[y:y+h, x:x+w])
#display the frame
cv2.imshow('frame', img)
#wait for 100 miliseconds
if cv2.waitKey(100) & 0xFF == ord('q'):
break
# break if the sample number is more than 100
elif sampleNum > 100:
break
cam.release()
cv2.destroyAllWindows()
temp=''.join(list(i for i in name.split()))
res = "Images Saved for ID : " + Id + " Name : " + temp + "Email :" + email
row = [Id, name,email]
with open("EmployeeDetails"+os.sep+"EmployeeDetails.csv", 'a+') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(row)
csvFile.close()
else:
if(isnumeric(Id)==False):
print("Enter Alphabetical Name")
else:
print("Enter correct email address")