Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- eye_image = cv2.imread("f.jpg")
- #_,image = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY)
- binary_eye_image = None
- if eye_image is not None:
- eye_histogram = [0]*256
- eye_image = cv2.cvtColor(eye_image, cv2.COLOR_RGB2GRAY)
- for i in xrange(256):
- value_count = (eye_image == i).sum()
- eye_histogram[i] = value_count
- count = 0
- index = 255
- while count < (eye_image.size*3/4):
- count += eye_histogram[index]
- index -= 1
- quarter_threshold = index
- #Multiply all parts of eye above bottom 1/4 brightness by 0
- #Might not work on people with light irises. Have not tried.
- binary_eye_image = cv2.equalizeHist((eye_image < quarter_threshold) * eye_image)
- relative_iris_coordinates = None
- if binary_eye_image is not None:
- eye_circles = cv2.HoughCircles(binary_eye_image, cv2.HOUGH_GRADIENT, 3, 500, maxRadius = binary_eye_image.shape[0]/5)
- if eye_circles is not None:
- #Usually gets the job done. Messy.
- circle = eye_circles[0][0]
- relative_iris_coordinates = (circle[0], circle[1])
- print relative_iris_coordinates
- cv2.imshow("hey", binary_eye_image)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement