Permalink
Browse files

Added python version

  • Loading branch information...
1 parent 523871a commit 7d163e28733c5587fed5874de70930d8237e0af9 @errollw committed Apr 7, 2014
Showing with 134,206 additions and 0 deletions.
  1. +2 −0 EyeTab_Python/anatomical_constants.py
  2. +79 −0 EyeTab_Python/calibrate_camera.py
  3. +15,452 −0 EyeTab_Python/cascades/haarcascade_eye.xml
  4. +26,161 −0 EyeTab_Python/cascades/haarcascade_frontalface_alt.xml
  5. +10,930 −0 EyeTab_Python/cascades/haarcascade_mcs_eyepair_big.xml
  6. +12,586 −0 EyeTab_Python/cascades/haarcascade_mcs_eyepair_small.xml
  7. +23,791 −0 EyeTab_Python/cascades/haarcascade_mcs_lefteye.xml
  8. +42,252 −0 EyeTab_Python/cascades/haarcascade_mcs_righteye.xml
  9. +126 −0 EyeTab_Python/conic_section.py
  10. +56 −0 EyeTab_Python/device_constants.py
  11. +168 −0 EyeTab_Python/draw_utils.py
  12. +69 −0 EyeTab_Python/eye_center_locator_combined.py
  13. +118 −0 EyeTab_Python/eye_center_locator_gradients.py
  14. +149 −0 EyeTab_Python/eye_center_locator_isophote.py
  15. +228 −0 EyeTab_Python/eye_extractor.py
  16. BIN EyeTab_Python/eye_images/abi1_l.png
  17. BIN EyeTab_Python/eye_images/abi1_r.png
  18. BIN EyeTab_Python/eye_images/abi2_l.png
  19. BIN EyeTab_Python/eye_images/abi2_r.png
  20. BIN EyeTab_Python/eye_images/andreas1_l.png
  21. BIN EyeTab_Python/eye_images/andreas1_r.png
  22. BIN EyeTab_Python/eye_images/andreas2_l.png
  23. BIN EyeTab_Python/eye_images/andreas2_r.png
  24. BIN EyeTab_Python/eye_images/andreas3_l.png
  25. BIN EyeTab_Python/eye_images/andreas3_r.png
  26. BIN EyeTab_Python/eye_images/andreas4_l.png
  27. BIN EyeTab_Python/eye_images/andreas4_r.png
  28. BIN EyeTab_Python/eye_images/andreas5_l.png
  29. BIN EyeTab_Python/eye_images/andreas5_r.png
  30. BIN EyeTab_Python/eye_images/andreas6_l.png
  31. BIN EyeTab_Python/eye_images/andreas6_r.png
  32. BIN EyeTab_Python/eye_images/david1_l.png
  33. BIN EyeTab_Python/eye_images/david1_r.png
  34. BIN EyeTab_Python/eye_images/erroll10_l.png
  35. BIN EyeTab_Python/eye_images/erroll10_r.png
  36. BIN EyeTab_Python/eye_images/erroll1_l.png
  37. BIN EyeTab_Python/eye_images/erroll1_r.png
  38. BIN EyeTab_Python/eye_images/erroll2_l.png
  39. BIN EyeTab_Python/eye_images/erroll2_r.png
  40. BIN EyeTab_Python/eye_images/erroll3_l.png
  41. BIN EyeTab_Python/eye_images/erroll3_r.png
  42. BIN EyeTab_Python/eye_images/erroll4_l.png
  43. BIN EyeTab_Python/eye_images/erroll4_r.png
  44. BIN EyeTab_Python/eye_images/erroll5_l.png
  45. BIN EyeTab_Python/eye_images/erroll5_r.png
  46. BIN EyeTab_Python/eye_images/erroll6_l.png
  47. BIN EyeTab_Python/eye_images/erroll6_r.png
  48. BIN EyeTab_Python/eye_images/erroll7_l.png
  49. BIN EyeTab_Python/eye_images/erroll7_r.png
  50. BIN EyeTab_Python/eye_images/erroll8_l.png
  51. BIN EyeTab_Python/eye_images/erroll8_r.png
  52. BIN EyeTab_Python/eye_images/erroll9_l.png
  53. BIN EyeTab_Python/eye_images/erroll9_r.png
  54. BIN EyeTab_Python/eye_images/george1_l.png
  55. BIN EyeTab_Python/eye_images/george1_r.png
  56. BIN EyeTab_Python/eye_images/hyesoon1_l.png
  57. BIN EyeTab_Python/eye_images/hyesoon1_r.png
  58. BIN EyeTab_Python/eye_images/hyesoon2_l.png
  59. BIN EyeTab_Python/eye_images/hyesoon2_r.png
  60. BIN EyeTab_Python/eye_images/james1_l.png
  61. BIN EyeTab_Python/eye_images/james1_r.png
  62. BIN EyeTab_Python/eye_images/james2_l.png
  63. BIN EyeTab_Python/eye_images/james2_r.png
  64. BIN EyeTab_Python/eye_images/mahdi1_l.png
  65. BIN EyeTab_Python/eye_images/mahdi1_r.png
  66. BIN EyeTab_Python/eye_images/mahdi2_l.png
  67. BIN EyeTab_Python/eye_images/mahdi2_r.png
  68. BIN EyeTab_Python/eye_images/osman1_l.png
  69. BIN EyeTab_Python/eye_images/osman1_r.png
  70. BIN EyeTab_Python/eye_images/osman2_l.png
  71. BIN EyeTab_Python/eye_images/osman2_r.png
  72. BIN EyeTab_Python/eye_images/phil1_l.png
  73. BIN EyeTab_Python/eye_images/phil1_r.png
  74. BIN EyeTab_Python/eye_images/phil2_l.png
  75. BIN EyeTab_Python/eye_images/phil2_r.png
  76. BIN EyeTab_Python/eye_images/phil3_l.png
  77. BIN EyeTab_Python/eye_images/phil3_r.png
  78. BIN EyeTab_Python/eye_images/phil4_l.png
  79. BIN EyeTab_Python/eye_images/phil4_r.png
  80. +259 −0 EyeTab_Python/eyelid_locator.py
  81. +101 −0 EyeTab_Python/find_limbus_points.py
  82. +63 −0 EyeTab_Python/fit_ellipse_numpy.py
  83. +157 −0 EyeTab_Python/gaze_geometry.py
  84. +62 −0 EyeTab_Python/gaze_smoothing.py
  85. +193 −0 EyeTab_Python/gaze_system.py
  86. +163 −0 EyeTab_Python/image_utils.py
  87. +50 −0 EyeTab_Python/limbus_outlier_removal.py
  88. +101 −0 EyeTab_Python/linpolar_transform.py
  89. +103 −0 EyeTab_Python/main.py
  90. +59 −0 EyeTab_Python/pre_processing.py
  91. +207 −0 EyeTab_Python/ransac_ellipse.py
  92. +116 −0 EyeTab_Python/ransac_eyelids.py
  93. +96 −0 EyeTab_Python/ray_casting.py
  94. +34 −0 EyeTab_Python/time_profiler.py
  95. +275 −0 EyeTab_Python/visualize_in_3d.py
@@ -0,0 +1,2 @@
+limbus_r_mm = 6
+eye_r_mm = 11
@@ -0,0 +1,79 @@
+import cv2, numpy as np, os
+
+board_w, board_h = 6, 9
+board_size = (board_w, board_h)
+
+img_w, img_h = 720, 1280
+img_size = (img_w, img_h)
+square_mm = 21
+
+def get_obect_img_pts(board_img, debug=False):
+
+ board_img_grey = cv2.cvtColor(board_img, cv2.COLOR_BGR2GRAY)
+
+ # Find chessboard corners
+ found, corners = cv2.findChessboardCorners(
+ image=board_img_grey,
+ patternSize=board_size,
+ flags=cv2.CALIB_CB_ADAPTIVE_THRESH | cv2.CALIB_CB_FILTER_QUADS | cv2.CALIB_CB_FAST_CHECK)
+
+ # Refine corner locations
+ cv2.cornerSubPix(
+ image=board_img_grey,
+ corners=corners,
+ winSize=(11, 11),
+ zeroZone=(-1, -1),
+ criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 30, 0.1))
+
+ if debug:
+ chessboard_debug_img = np.copy(board_img)
+ chessboard_debug_img = cv2.cvtColor(chessboard_debug_img,cv2.COLOR_BGR2GRAY)
+ chessboard_debug_img = cv2.cvtColor(chessboard_debug_img,cv2.COLOR_GRAY2BGR)
+ cv2.drawChessboardCorners(chessboard_debug_img, board_size, corners, found)
+ cv2.imshow("board", chessboard_debug_img)
+ cv2.waitKey()
+
+ # Correctly arrange arrays of corresponding points
+ object_pts = np.zeros((np.prod(board_size), 3), np.float32)
+ object_pts[:, :2] = np.indices(board_size).T.reshape(-1, 2) * square_mm
+ image_pts = corners.reshape(-1, 2)
+
+ return object_pts, image_pts
+
+
+def get_intrinsic_camera_params(object_pts, image_pts, debug=False):
+
+ _, cam_mat, dist_coefs, _, _ = cv2.calibrateCamera(
+ objectPoints=object_pts,
+ imagePoints=image_pts,
+ imageSize=img_size)
+
+ if debug:
+ print dist_coefs
+ print cam_mat
+ print 'fx = {}, fy = {}'.format(cam_mat[0][0], cam_mat[1][1])
+ print 'cx = {}, cy = {}'.format(cam_mat[0][2], cam_mat[1][2])
+
+ return cam_mat, dist_coefs
+
+
+#----------------------------------------
+# FIND INTRINSIC CAMERA PARAMETERS
+#----------------------------------------
+if __name__ == '__main__':
+
+ calibration_imgs_path = 'camera_calibration'
+ calibration_imgs = map(lambda x: cv2.imread(os.path.join(calibration_imgs_path, x)),
+ os.listdir(calibration_imgs_path))
+
+ all_object_pts, all_img_pts = [], []
+ for img in calibration_imgs:
+ object_pts, image_pts = get_obect_img_pts(img, debug=True)
+ all_object_pts.append(object_pts)
+ all_img_pts.append(image_pts)
+
+ cam_mat, dist_coefs = get_intrinsic_camera_params(all_object_pts, all_img_pts, True)
+
+ params_file = open('camera_matrix_N7.txt', 'w')
+ params_file.write('fx = {}\nfy = {}\ncx = {}\ncy = {}'.format(cam_mat[0][0], cam_mat[1][1], cam_mat[0][2], cam_mat[1][2]))
+ params_file.close()
Oops, something went wrong.

0 comments on commit 7d163e2

Please sign in to comment.