Skip to content
Snippets Groups Projects
Commit 151829f6 authored by shreyasb's avatar shreyasb
Browse files

updates

parent 6f21cdc0
Branches
No related tags found
No related merge requests found
......@@ -101,12 +101,15 @@ def main():
data = tobiiglasses.get_data()
if len(eye_data) > max_len:
eye_data.pop(0)
# 3d gaze coordinate data
gaze_data = data['gp3']
# timestamp
ts = gaze_data['ts']
# print("ts in main", ts)
# print("gaze_data in main", gaze_data)
if 'gp3' in gaze_data.keys():
# 3d gaze coordinate
gaze3 = gaze_data['gp3']
else:
gaze3 = [-1] * 3
......@@ -122,6 +125,7 @@ def main():
gray_frame = cv2.cvtColor(gray_frame, cv2.COLOR_BGR2GRAY)
result = detector.detect(gray_frame)
# pupil diameter
if 'pd' in data['left_eye']['pd'].keys():
pd_left = data['left_eye']['pd']['pd']
else:
......@@ -171,7 +175,8 @@ def main():
elapsed_one_iter = time.time() - comp_start_time
if elapsed_one_iter < camera_rate * 1e-3:
time.sleep(camera_rate * 1e-3 - elapsed_one_iter)
else:
print("Took %2.2f s longer for computations"%(elapsed_one_iter - camera_rate * 1e-3))
elapsed = time.time() - start
if elapsed > test_time:
......
......@@ -113,18 +113,13 @@ def main():
gaze3 = gaze_data['gp3']
else:
gaze3 = [-1] * 3
if len(gaze3) < 4:
if len(gaze3) < 4: # Homogenizing
gaze3.append(1)
# print("gaze3 in main", gaze3)
# gaze3 = np.array(gaze3)
_, frame = cap.read()
gray_frame = cv2.resize(frame, (640, 360))
gray_frame = cv2.cvtColor(gray_frame, cv2.COLOR_BGR2GRAY)
result = detector.detect(gray_frame)
# pupil diameter
if 'pd' in data['left_eye']['pd'].keys():
pd_left = data['left_eye']['pd']['pd']
......@@ -135,6 +130,19 @@ def main():
else:
pd_right = -1
# Right eye pupil postion
Pc_right = data['right_eye']['pc']
if 'pc' in Pc_right.keys():
pc_right = Pc_right['pc']
else:
pc_right = [-1] * 3
_, frame = cap.read()
gray_frame = cv2.resize(frame, (640, 360))
gray_frame = cv2.cvtColor(gray_frame, cv2.COLOR_BGR2GRAY)
result = detector.detect(gray_frame)
if not(gaze3[0] == -1 and gaze3[1] == -1 and gaze3[2] == -1 or pd_left == -1 or pd_right == -1):
gaze3[0] = -gaze3[0]
gaze3[1] = -gaze3[1]
......@@ -164,7 +172,7 @@ def main():
# # LOOKING AT SCREEN 3 ###
# gaze_screen = 3
if ts not in eye_data:
eye_data.append([ts, gaze3, gaze_mapped, gaze_screen])
eye_data.append([ts, gaze3, pc_right, gaze_mapped, gaze_screen])
if len(eye_data) < min_len:
continue
......@@ -209,7 +217,6 @@ def increment_fixations(data, AOIfixations):
i = 0
length = len(data[1])
while i < length:
screen = -1
single_fix_data = []
......@@ -244,15 +251,17 @@ def dot(v1, v2):
return dot_prod
def calculateVelocity(ts1, gp3_1, ts2, gp3_2):
def calculateVelocity(ts1, gp3_1, ts2, gp3_2, pc_right_1, pc_right_2):
# print("gp3_1", gp3_1)
# print("gp3_2", gp3_2)
# print("ts1", ts1)
# print("ts2", ts2)
cross_prod = cross(gp3_1, gp3_2)
dot_prod = dot(gp3_1, gp3_2)
v1 = gp3_1 - pc_right_1
v2 = gp3_2 - pc_right_2
cross_prod = cross(v1, v2)
dot_prod = dot(v1, v2)
angle = math.atan2(cross_prod, dot_prod) * 180 / math.pi
......@@ -261,7 +270,6 @@ def calculateVelocity(ts1, gp3_1, ts2, gp3_2):
return vel
def computeFixations(eye_data, vel_threshold, total_fixations, num_fixations_in_window, AOIfixations):
fix_num = 1
......@@ -270,13 +278,18 @@ def computeFixations(eye_data, vel_threshold, total_fixations, num_fixations_in_
for i in range(1, len(eye_data)):
ts1 = eye_data[i - 1][0]
gp3_1 = eye_data[i - 1][1]
gp3_1 = eye_data[i - 1][1][:3]
pc_right_1 = eye_data[i - 1][2]
ts2 = eye_data[i][0]
gp3_2 = eye_data[i][1]
if ts1 == ts2:
gp3_2 = eye_data[i][1][:3]
pc_right_2 = eye_data[i][2]
invalid_data_1 = pc_right_1 == [-1, -1, -1]
invalid_data_2 = pc_right_2 == [-1, -1, -1]
if ts1 == ts2 or invalid_data_1 or invalid_data_2:
continue
vel = calculateVelocity(ts1, gp3_1, ts2, gp3_2)
vel = calculateVelocity(ts1, gp3_1, ts2, gp3_2, pc_right_1, pc_right_2)
if vel < vel_threshold:
fix_num_changed = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment