diff --git a/__pycache__/find_pupil.cpython-37.pyc b/__pycache__/find_pupil.cpython-37.pyc new file mode 100644 index 0000000..0d02268 Binary files /dev/null and b/__pycache__/find_pupil.cpython-37.pyc differ diff --git a/find_pupil.py b/find_pupil.py index 48d23bc..0b4f3e8 100644 --- a/find_pupil.py +++ b/find_pupil.py @@ -83,7 +83,12 @@ def pupil_contour(img, threshold, debug=1): #for this image #print(threshold) contours, _ = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) - best_contour = np.empty(contours[1].shape) #Empty Contour + + + if len(contours) == 1 : + best_contour = np.empty(contours[0].shape) #Empty Contour + else: + best_contour = np.empty(contours[1].shape) #Empty Contour for contour in contours: area = cv2.contourArea(contour) if PUPIL_MAX > area > PUPIL_MIN: @@ -108,7 +113,10 @@ def pupil_contour(img, threshold, debug=1): # pylint: disable=R1715 if contour_candidates == []: #if nothing found - return np.empty(contours[1].shape) + if len(contours) > 1: + return np.empty(contours[1].shape) + else: + return np.empty(contours[0].shape) else: #get best candidate (top circularity for now) sorted_contour_candidates = sorted(contour_candidates, \ diff --git a/frame.bmp b/frame.bmp new file mode 100644 index 0000000..19ab62b Binary files /dev/null and b/frame.bmp differ diff --git a/graph_variance.py b/graph_variance.py index 15cc861..6faab81 100644 --- a/graph_variance.py +++ b/graph_variance.py @@ -14,7 +14,6 @@ import matplotlib.pyplot as plt from find_pupil import pupillometry import numpy -import pandas as pd #text FONT = cv2.FONT_HERSHEY_SIMPLEX SMI_DIM = (720, 480) # Dimension from SMI System @@ -83,6 +82,16 @@ def display_main(frame, cap): cv2.imshow('Frame', resized_frame) #cv2.waitKey(0) +def display_left(left): + """ Display the Left Eye""" + resized_left = resize_with_aspect_ratio(left, width=640) #Resize by\ + # pylint: disable=C0103 + L_STRING = "Left" + cv2.putText(resized_left, L_STRING, (0, 20), FONT, 0.8, (0, 255, 0), 2, cv2.LINE_AA) + cv2.imshow('Left Eye', resized_left) + #cv2.waitKey(0) + # resized_frame = ResizeWithAspectRatio(frame, height = 480) + def best_fit(rads, radius): fitted = numpy.polyfit(rads, radius, 7) #print('best fit: ', fitted) @@ -146,9 +155,11 @@ def main(frame=-1, filename=DEFAULT_FILE_NAME): cv2.imwrite("frame.bmp", frame) - _, rads, radius = pupillometry(frame, debug) + image_edit, rads, radius = pupillometry(frame, debug) display_main(frame, cap) + display_left(image_edit) + try: best_fit(rads, radius) except numpy.linalg.LinAlgError as er: diff --git a/outputcsv.csv b/outputcsv.csv new file mode 100644 index 0000000..e2876e6 --- /dev/null +++ b/outputcsv.csv @@ -0,0 +1 @@ +timestamp (ms),data (radius,radians)