iris detection using hough circle

55 Views Asked by At

I am trying to detect iris using HoughCircles and i need two circle differntiating pupil and iris and the sclera but i am getting only 1 circle and that also not in the correct eye part

this is my code and the image is my final output :

import cv2
import numpy as np
import os
import fnmatch
from PIL import Image
import matplotlib.pyplot as plt

output_save_path = "output.png"
root = 'C:\\Users\\sreek\\Desktop\\iris\\imgs\\training_images\\train_images_0-150'
pattern = ".JPG"
eye_cascade = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml')

for path, subdirs, files in os.walk(root):
    for f in files:

        img_array = cv2.imread(os.path.join(path, f)) 
        color_img = Image.fromarray(cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB))
        eyes = eye_cascade.detectMultiScale(img_array, scaleFactor=1.3, minNeighbors=5)
        for i, (x, y, w, h) in enumerate(eyes):
            eye_img = img_array[y:y+h, x:x+w]
            
            gray_eye_img = cv2.cvtColor(np.array(eye_img), cv2.COLOR_BGR2GRAY)
            canny = cv2.Canny(np.array(gray_eye_img), 50,50)
            
            circles = cv2.HoughCircles(canny, cv2.HOUGH_GRADIENT, 1, 10000, param1 = 50, param2 = 30, minRadius = 50, maxRadius = 200)
            if circles is not None:
                circles = np.uint16(np.around(circles))
                # circle_img = np.zeros_like(eye_img)    
                for i in circles[0,:]:
                    # draw the outer circle
                    x, y, r = i[0], i[1], i[2]
                    cv2.circle(eye_img,(x, y),r,(0,255,0),2)
                    # draw the center of the circle
                    cv2.circle(eye_img,(x, y),1,(0,0,255),3)
            
                    plt.imshow(cv2.cvtColor(np.array(eye_img), cv2.COLOR_BGR2RGB))
                    plt.show()
0

There are 0 best solutions below