-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataSetCreator.py
More file actions
61 lines (51 loc) · 1.75 KB
/
Copy pathdataSetCreator.py
File metadata and controls
61 lines (51 loc) · 1.75 KB
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
import cv2
import numpy as np
import sqlite3
def insertOrUpdate(Name,Age,Gen,Loc):
conn=sqlite3.connect("facerecognition.db")
cursor= conn.execute('SELECT max(Id) from People')
Id = cursor.fetchone()[0]
if(Id == None):
Id=0
Id+=1
cmd="SELECT * FROM People WHERE ID = "+str(Id)
cursor=conn.execute(cmd)
isRecordExist=0
for row in cursor:
isRecordExist=1
if(isRecordExist==1):
conn.execute("UPDATE People SET Name =? WHERE ID =?",(Name,Id))
conn.execute("UPDATE People SET Age =? WHERE ID =?",(Age,Id))
conn.execute("UPDATE People SET Gender =? WHERE ID =?",(Gen,Id))
conn.execute("UPDATE People SET Location =? WHERE ID =?",(Loc,Id))
else:
params= (Id, Name, Age, Gen, Loc)
conn.execute("INSERT INTO People Values(?, ?, ?, ?, ?)",params)
cmd2=""
cmd3=""
conn.commit()
conn.close()
return Id
def test(form_name, form_age, form_gen, form_loc):
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);
name = str(form_name)
age = int(form_age)
gen = form_gen
loc = str(form_loc)
Id=insertOrUpdate(name,age,gen,loc)
sampleNum=0
while(True):
ret,img=cam.read();
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceDetect.detectMultiScale(gray,1.1,5);
for(x,y,w,h) in faces:
sampleNum=sampleNum+1;
cv2.imwrite("dataSet/User."+str(Id)+"."+str(sampleNum)+".jpg",gray[y:y+h,x:x+w])
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
cv2.waitKey(50);
cv2.imshow("Face",img);
if(sampleNum>30):
break;
cam.release()
cv2.destroyAllWindows()