-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_prep.py
58 lines (41 loc) · 1.22 KB
/
data_prep.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
# coding: utf-8
# In[33]:
import cv2
import numpy as np
# In[36]:
import cv2
import numpy as np
inputname=input("your name")
path="/home/gopal/Desktop/face_reco/numpy_data/"
cap=cv2.VideoCapture(1)
face_cascde=cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
skip=0
face_data=[]
while True:
ret,frame=cap.read()
if ret==False:
continue
gray_fram=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces=face_cascde.detectMultiScale(frame,1.3,5)
for face in faces:
x,w,y,h=face
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,255),2)
off=10
intrested_face=gray_fram[y+off:y+h+off,x+off:x+w+off]
intrested_face=cv2.resize(intrested_face,(100,100))
skip+=1
if skip%20==0:
face_data.append(intrested_face)
print len(face_data)
#print faces
cv2.imshow("Frame",frame)
key_press=cv2.waitKey(1) & 0xFF
if key_press==ord('q'):
break
face_data=np.asarray(face_data)
face_data=face_data.reshape((face_data.shape[0],-1))
print face_data.shape
np.save(path+inputname+'.npy',face_data)
cap.release()
cv2.destroyAllWindows()
cv2.waitKey(1)