This repository was archived by the owner on Aug 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDATABASE_CREATION.py
More file actions
68 lines (47 loc) · 1.69 KB
/
DATABASE_CREATION.py
File metadata and controls
68 lines (47 loc) · 1.69 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
62
63
64
65
66
67
68
import matplotlib.pyplot as plt
import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier(r'C:\ProgramData\Anaconda3\Lib\site-packages\cv2\data\haarcascade_frontalface_default.xml')
#https://github.com/Itseez/opencv/blob/master/data/haarcascades/haarcascade_eye.xml
eye_cascade = cv2.CascadeClassifier(r'C:\ProgramData\Anaconda3\Lib\site-packages\cv2\data\haarcascade_eye.xml')
cap = cv2.VideoCapture(0)
all_faces = []
thiz = []
for dff in range(5000):
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
roi_gray = cv2.resize(roi_gray, (256, 256))
all_faces.append(roi_gray)
cv2.imshow('img',roi_gray)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
for i in range(len(all_faces)):
path = r'C:\Users\dbryc\Desktop\images'
name = 'im'+str(i)+'.jpg'
f = os.path.join(path, name)
cv2.imwrite(f, faces[i])
cap.release()
cv2.destroyAllWindows()
for img in (os.listdir(r'C:\Users\HP\OneDrive\Pictures\COPIED')):
path = os.path.join(r'C:\Users\HP\OneDrive\Pictures\COPIED', img)
img = cv2.imread(path,0)
images.append(img)
def extracteyes(data):
asd = []
for i in range(len(data)):
t = []
eyes = eye_cascade.detectMultiScale(images[i])
for (ex,ey,ew,eh) in eyes:
eyes = images[i][ey:ey+eh, ex:ex+ew]
if np.shape(eyes)[0] >38:
eyes = cv2.resize(eyes, (50,50))
t.append(eyes)
asd.append(t)
return asd
GitHub