-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy patheyes_detection.py
106 lines (62 loc) · 2.34 KB
/
eyes_detection.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import cv2
import numpy as np
import glob
import pickle
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
eye_num_2=0
def transform_image(img,threshold):
retval, threshold = cv2.threshold(img, threshold, 255, cv2.THRESH_BINARY)
opening = cv2.morphologyEx(threshold, cv2.MORPH_OPEN, kernel)
closing = cv2.morphologyEx(threshold, cv2.MORPH_CLOSE, kernel)
open_close = cv2.bitwise_or(opening, closing, mask = None)
return open_close,opening,closing
imgs = []
label=0
final_output = []
lables = []
'''
for filepath in glob.iglob('test/*'):
if filepath[-1] == 'g':
img = cv2.imread(filepath)
img=cv2.resize(img,(200,150))
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgs.append([img,filepath])
print(filepath)
'''
#'''
for filepath in glob.iglob('UBIRIS_200_150/Sessao_1/*'):
num_in_folder= 0
for filefilepath in glob.iglob(filepath+'/*'):
if filefilepath[-1] == 'g':
img = cv2.imread(filefilepath)
imgs_colored=cv2.imread(filefilepath)
img=cv2.resize(img,(400,300))
#imgs_colored.append(img)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgs.append([img,num_in_folder,label,imgs_colored])
num_in_folder=num_in_folder+1
label = label+1
#'''
eyes_num=0
for i,j,L,c in imgs:
#cv2.imshow('dd',i)
eyes = eye_cascade.detectMultiScale(i, 1.01, 0)
if len(eyes)>1:
eyes_num = eyes_num+1
maxium_area = -3
for (ex,ey,ew,eh) in eyes:
area = ew*eh
if area>maxium_area:
maxium_area = area
maxium_width=ew
point_x=ex
point_y=ey
maxium_height = eh
cv2.rectangle(c,(point_x,point_y),(point_x+maxium_width,+maxium_height),(255,0,0),2) #cv2.imwrite('paper/threshold/'+str(L)+'.'+str(j)+'.jpg',working_img)
#cv2.imwrite('paper/eyes/'+str(L)+'.'+str(j)+'.jpg',c)
#roi_gray = gray[y:y+h, x:x+w]
#roi_gray = gray[ey:ey+eh, ex:ex+ew]
#roi_color = img[ey:ey+eh, ex:ex+ew]
print("total_eyes_found = ",eyes_num)
print("total_eyes_found 2 = ",eye_num_2)
print("total images number ",len(imgs))