Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import cv2
  2.  
  3. eye_image = cv2.imread("f.jpg")
  4.  
  5. #_,image = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY)
  6.  
  7. binary_eye_image = None
  8. if eye_image is not None:
  9. eye_histogram = [0]*256
  10. eye_image = cv2.cvtColor(eye_image, cv2.COLOR_RGB2GRAY)
  11. for i in xrange(256):
  12. value_count = (eye_image == i).sum()
  13. eye_histogram[i] = value_count
  14. count = 0
  15. index = 255
  16. while count < (eye_image.size*3/4):
  17. count += eye_histogram[index]
  18. index -= 1
  19. quarter_threshold = index
  20. #Multiply all parts of eye above bottom 1/4 brightness by 0
  21. #Might not work on people with light irises. Have not tried.
  22. binary_eye_image = cv2.equalizeHist((eye_image < quarter_threshold) * eye_image)
  23.  
  24. relative_iris_coordinates = None
  25. if binary_eye_image is not None:
  26. eye_circles = cv2.HoughCircles(binary_eye_image, cv2.HOUGH_GRADIENT, 3, 500, maxRadius = binary_eye_image.shape[0]/5)
  27. if eye_circles is not None:
  28. #Usually gets the job done. Messy.
  29. circle = eye_circles[0][0]
  30. relative_iris_coordinates = (circle[0], circle[1])
  31.  
  32. print relative_iris_coordinates
  33.  
  34.  
  35.  
  36. cv2.imshow("hey", binary_eye_image)
  37. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement