forked from OmarMedhat22/Iris-Recognition-on-Ubiris-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eyes_iris_detection.py
141 lines (82 loc) · 3.19 KB
/
eyes_iris_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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)
imgs_colored=cv2.resize(imgs_colored,(400,300))
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
#'''
iris_num=0
for i,j,L,c in imgs:
circles = cv2.HoughCircles(i, cv2.HOUGH_GRADIENT, 10, 100)
if circles is not None :
circles = np.round(circles[0, :]).astype("int")
#print(len(circles))
#print(y)
maxiumum_average=10000000000000
#print(len(circles))
#print(i.shape[0])
#print(i.shape[1])
#print(min(i.shape))
key=True
for (x, y, r) in circles:
if x+r<=max(i.shape) and y+r<=max(i.shape)and x-r>0 and y-r>0 and r>20:
key=False
new_roi = i[y-r:y+r, x-r:x+r]
average = np.average(new_roi)
if average < maxiumum_average:
maxiumum_r = r
point_x=x
point_y=y
maxiumum_average=average
#cv2.circle(i, (x, y), r, (0, 0, 0), 4)
if key:
print("key opened")
for (x, y, r) in circles:
maxiumu_raduis=-4
if r > maxiumu_raduis:
maxiumum_r = r
point_x=x
point_y=y
maxiumum_average=average
cv2.circle(c, (point_x, point_y), maxiumum_r, (255, 255, 0), 4)
print(str(L)+'.'+str(j)+" = "+str(maxiumum_average)+" "+str(r))
cv2.imwrite('paper/iris/'+str(L)+'.'+str(j)+'.jpg',c)
iris_num = iris_num+1
#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_iris_found = ",iris_num)
print("total images number ",len(imgs))