-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
85 lines (56 loc) · 2.26 KB
/
main.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
#Vinícius Matiola Tramontin
import cv2
import numpy as np
from matplotlib import pyplot as plt
def hough(img, cont, window_num):
fig = plt.figure(window_num, figsize=(8, 8))
_, thresh = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY)
circles = cv2.HoughCircles(thresh, cv2.HOUGH_GRADIENT, 2, 160, param1=20, param2=20, minRadius=100, maxRadius=180)
circles = np.uint16(np.around(circles))
x_iris = circles[0][0][0]
y_iris = circles[0][0][1]
radius_iris = circles[0][0][2]
mask_iris = np.zeros_like(img)
mask_iris = cv2.circle(mask_iris, (x_iris,y_iris), radius_iris, (255,255,255), -1)
res = cv2.bitwise_and(img, img, mask = mask_iris)
circles_pupil = cv2.HoughCircles(res, cv2.HOUGH_GRADIENT, 2, 160, param1=20, param2=20, minRadius=54, maxRadius=80)
circles_pupil = np.uint16(np.around(circles_pupil))
x_pupil = circles_pupil[0][0][0]
y_pupil = circles_pupil[0][0][1]
radius_pupil = circles_pupil[0][0][2]
mask_pupil = np.zeros_like(img)
mask_pupil = cv2.circle(mask_pupil, (x_pupil,y_pupil), radius_pupil, (255,255,255), -1)
mask = cv2.subtract(mask_iris, mask_pupil)
res = cv2.bitwise_and(res, res, mask = mask)
plt.gray()
fig.add_subplot(2, 2, cont)
plt.xticks([])
plt.yticks([])
plt.imshow(img)
fig.add_subplot(2, 2, cont+1)
plt.xticks([])
plt.yticks([])
plt.imshow(res)
window_num = 0
for i in range(1, 11):
for j in range(1, 6):
imgR = None
imgL = None
caminhoR = ''
caminhoL = ''
if i < 10:
caminhoR = './Amostras/00' + str(i) + '_R_0' + str(j) + '.JPG'
caminhoL = './Amostras/00' + str(i) + '_L_0' + str(j) + '.JPG'
else:
caminhoR = './Amostras/0' + str(i) + '_R_0' + str(j) + '.JPG'
caminhoL = './Amostras/0' + str(i) + '_L_0' + str(j) + '.JPG'
imgR = cv2.imread(caminhoR)
imgL = cv2.imread(caminhoL)
croppedR = imgR[500:500+900, 700:700+1200].copy()
croppedL = imgL[500:500+900, 700:700+1200].copy()
grayR = cv2.cvtColor(croppedR, cv2.COLOR_BGR2GRAY)
grayL = cv2.cvtColor(croppedL, cv2.COLOR_BGR2GRAY)
hough(grayR, 1, window_num)
hough(grayL, 3, window_num)
plt.show()
window_num += 1