Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/find_pupil.cpython-37.pyc
Binary file not shown.
12 changes: 10 additions & 2 deletions find_pupil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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, \
Expand Down
Binary file added frame.bmp
Binary file not shown.
15 changes: 13 additions & 2 deletions graph_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions outputcsv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
timestamp (ms),data (radius,radians)