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

laptop updates

parents ef9c5178 ea037f56
Branches
No related tags found
No related merge requests found
Old reference photos/screen1.jpg

276 KiB | W: | H:

Old reference photos/screen1.jpg

268 KiB | W: | H:

Old reference photos/screen1.jpg
Old reference photos/screen1.jpg
Old reference photos/screen1.jpg
Old reference photos/screen1.jpg
  • 2-up
  • Swipe
  • Onion skin
Old reference photos/screen2.jpg

478 KiB | W: | H:

Old reference photos/screen2.jpg

377 KiB | W: | H:

Old reference photos/screen2.jpg
Old reference photos/screen2.jpg
Old reference photos/screen2.jpg
Old reference photos/screen2.jpg
  • 2-up
  • Swipe
  • Onion skin
background.jpg

569 KiB

......@@ -17,7 +17,7 @@ blank_image = np.ones((height,width,3), np.uint8) * 255
# img = cv2.resize(img,img_size)
# imgs[i] = img
# name = "img" + str(i)
# # cv2.imshow(name, img)
# cv2.imshow(name, img)
for i in range(3):
# x = width / 3 * i + width/3/3
......
......@@ -46,8 +46,8 @@ def main():
# saccade_data_full = []
# uncalssified (very short fixations) data holders
AOIunclassified = []
AOIunclassifiedDurations = []
AOIunclassified = [0] * 4
AOIunclassifiedDurations = [0] * 4
last_ts = 0
......@@ -58,8 +58,8 @@ def main():
# discard_short_fixations
# merge_close_fixations
test_time = 60
camera_rate = 30
test_time = 15
camera_rate = 25
num_apriltags = 15
cap = cv2.VideoCapture(0)
......@@ -75,7 +75,7 @@ def main():
# tobiiglasses.stop_streaming()
sys.exit(1)
background = cv2.imread('background36h11.jpg')
background = cv2.imread('background.jpg')
background = cv2.resize(background, (640, 360))
gray_back = cv2.cvtColor(background, cv2.COLOR_RGB2GRAY)
# detector = Detector(families='tag25h9', nthreads=1, quad_decimate=1.0)
......@@ -125,6 +125,7 @@ def main():
P2 = np.dot(P2, config.Rigid_body)
start = time.time()
bg_copy = background.copy()
tobiiglasses.start_streaming()
while True:
......@@ -183,7 +184,7 @@ def main():
gaze3[1] = -gaze3[1]
gaze_screen = -1
gaze_mapped = np.dot(P2, gaze3) ## 3X1
gaze_mapped = gaze_mapped/gaze_mapped[2]
gaze_mapped[0] = gaze_mapped[0] / 1920*640 ## TODO: Need to check 1920 -> 640
......@@ -193,28 +194,28 @@ def main():
if H is not None:
gaze_mapped = np.dot(H, gaze_mapped)
gaze_mapped = gaze_mapped/gaze_mapped[2]
# cv2.circle(bg_copy, (int(gaze_mapped_back[0]), int(gaze_mapped_back[1])), 2, (0,0,255), 40)
# cv2.circle(bg_copy, (int(gaze_mapped[0]), int(gaze_mapped[1])), 2, (255,0,0), 20)
if gaze_mapped[0] > s1_min_x and gaze_mapped[1] > s1_min_y and gaze_mapped[0] < s1_max_x and gaze_mapped[1] < s1_max_y:
## LOOKING AT SCREEN1######
print("Looking at screen 1", end='\r')
gaze_screen = 1
if last_ts != 0:
AOIgazeDuration[gaze_screen - 1] += ts - last_ts
AOIgazeDuration[gaze_screen - 1] += 1e-6 * (ts - last_ts)
elif gaze_mapped[0] > s2_min_x and gaze_mapped[1] > s2_min_y and gaze_mapped[0] < s2_max_x and gaze_mapped[1] < s2_max_y: # and gaze_mapped[1] > 180:
# LOOKING AT SCREEN2 ######
print("Looking at screen 2", end='\r')
gaze_screen = 2
if last_ts != 0:
AOIgazeDuration[gaze_screen - 1] += ts - last_ts
AOIgazeDuration[gaze_screen - 1] += 1e-6 * (ts - last_ts)
elif gaze_mapped[0] > s3_min_x and gaze_mapped[1] > s3_min_y and gaze_mapped[0] < s3_max_x and gaze_mapped[1] < s3_max_y:
# LOOKING AT SCREEN 3 ###
print("Looking at screen 3", end='\r')
gaze_screen = 3
if last_ts != 0:
AOIgazeDuration[gaze_screen - 1] += ts - last_ts
AOIgazeDuration[gaze_screen - 1] += 1e-6 * (ts - last_ts)
else:
print("Looking at screen 0", end='\r')
......@@ -261,6 +262,7 @@ def main():
AOIfixations[curr_screen] += 1
duration = 1e-6 * (eye_data[0][0] - fixations_data[0][0])
fix_center = get_fix_center(fixations_data)
cv2.circle(bg_copy, (int(fix_center[0]), int(fix_center[1])), 2, (250,0,0), 20)
# data_to_append = get_data_to_append(fixations_data, 'fix', fix_center, AOIfixations[curr_screen], duration)
# full_class_data.append(data_to_append)
fixations_centers_data.append([fix_center, curr_screen, duration])
......@@ -276,6 +278,12 @@ def main():
fixations_data = []
# else:
# cv2.imshow("frame", bg_copy)
# if cv2.waitKey(20) & 0xFF == ord('q'):
# print()
# break
elapsed_one_iter = time.time() - comp_start_time
if elapsed_one_iter < 1 / camera_rate:
time.sleep(1 / camera_rate - elapsed_one_iter)
......@@ -287,6 +295,7 @@ def main():
print()
break
cv2.imwrite("fix_centers_1.png", bg_copy)
tobiiglasses.stop_streaming()
return AOIfixations, AOIsaccades, AOIfixationDurations, AOIsaccadeDurations, total_fixations, total_saccades, AOIgazeDuration, AOIunclassified, AOIunclassifiedDurations, fixations_centers_data
......
......@@ -7,17 +7,19 @@ import time
import math
import config
import socket
from signal import SIGINT, signal
tobii_ip = '192.168.71.50'
tobiiglasses = TobiiGlassesController(tobii_ip, video_scene=True)
def main():
# iMotions connection settings
iMotions_ip = '192.168.71.60'
port = 8125
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((iMotions_ip, port))
tobii_ip = '192.168.71.50'
tobiiglasses = TobiiGlassesController(tobii_ip, video_scene=True)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# s.connect((iMotions_ip, port))
project_id = tobiiglasses.create_project("Test live_scene_and_gaze.py")
participant_id = tobiiglasses.create_participant(project_id, "participant_test")
......@@ -34,6 +36,7 @@ def main():
camera_rate = 30
num_apriltags = 15
test_time = 60
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG"))
......@@ -48,7 +51,7 @@ def main():
# tobiiglasses.stop_streaming()
sys.exit(1)
background = cv2.imread('background36h11.jpg')
background = cv2.imread('background.jpg')
background = cv2.resize(background, (640, 360))
gray_back = cv2.cvtColor(background, cv2.COLOR_RGB2GRAY)
......@@ -97,12 +100,18 @@ def main():
P2 = np.dot(config.K2, Ex)
P2 = np.dot(P2, config.Rigid_body)
print("Checking calibration...")
calibration_success = False
# start = time.time()
tobiiglasses.start_streaming()
while True:
comp_start_time = time.time()
if not calibration_success:
bg_copy = background.copy()
data = tobiiglasses.get_data()
# 3d gaze coordinate data
......@@ -174,36 +183,55 @@ def main():
if H is not None:
gaze_mapped = np.dot(H, gaze_mapped)
gaze_mapped = gaze_mapped/gaze_mapped[2]
# cv2.circle(bg_copy, (int(gaze_mapped_back[0]), int(gaze_mapped_back[1])), 2, (0,0,255), 40)
if gaze_mapped[0] > s1_min_x and gaze_mapped[1] > s1_min_y and gaze_mapped[0] < s1_max_x and gaze_mapped[1] < s1_max_y:
## LOOKING AT SCREEN1######
print("Looking at screen 1", end='\r')
gaze_screen = 1
elif gaze_mapped[0] > s2_min_x and gaze_mapped[1] > s2_min_y and gaze_mapped[0] < s2_max_x and gaze_mapped[1] < s2_max_y: # and gaze_mapped[1] > 180:
# LOOKING AT SCREEN2 ######
print("Looking at screen 2", end='\r')
gaze_screen = 2
elif gaze_mapped[0] > s3_min_x and gaze_mapped[1] > s3_min_y and gaze_mapped[0] < s3_max_x and gaze_mapped[1] < s3_max_y:
# LOOKING AT SCREEN 3 ###
print("Looking at screen 3", end='\r')
gaze_screen = 3
else:
print("Looking at screen 0", end='\r')
gaze_screen = -1
msg = generate_message(ts, gaze3, gaze_mapped, pd, gaze_screen, pc_left, pc_right)
# print(msg)
s.send(msg)
if not calibration_success:
cv2.circle(bg_copy, (int(gaze_mapped[0]), int(gaze_mapped[1])), 2, (0,0,255), 40)
cv2.imshow("Background", bg_copy)
print("Check mapping. Press y if mapping is good, ctrl-c if not", end='\r')
if cv2.waitKey(10) & 0xFF == ord('y'):
calibration_success = True
print()
print("Calibration correct...")
print("Hit ctrl+c to end recording")
cv2.destroyAllWindows()
if calibration_success:
if gaze_mapped[0] > s1_min_x and gaze_mapped[1] > s1_min_y and gaze_mapped[0] < s1_max_x and gaze_mapped[1] < s1_max_y:
## LOOKING AT SCREEN1######
print("Looking at screen 1", end='\r')
gaze_screen = 1
elif gaze_mapped[0] > s2_min_x and gaze_mapped[1] > s2_min_y and gaze_mapped[0] < s2_max_x and gaze_mapped[1] < s2_max_y: # and gaze_mapped[1] > 180:
# LOOKING AT SCREEN2 ######
print("Looking at screen 2", end='\r')
gaze_screen = 2
elif gaze_mapped[0] > s3_min_x and gaze_mapped[1] > s3_min_y and gaze_mapped[0] < s3_max_x and gaze_mapped[1] < s3_max_y:
# LOOKING AT SCREEN 3 ###
print("Looking at screen 3", end='\r')
gaze_screen = 3
else:
print("Looking at screen 0", end='\r')
gaze_screen = -1
msg = generate_message(ts, gaze3, gaze_mapped, pd, gaze_screen, pc_left, pc_right)
# print(msg)
# s.send(msg)
# if calibration_success:
s.sendto(msg, (iMotions_ip, port))
elapsed_one_iter = time.time() - comp_start_time
if elapsed_one_iter < 1 / camera_rate:
time.sleep(1 / camera_rate - elapsed_one_iter)
# elapsed = time.time() - start
# if elapsed > test_time:
# print()
# break
tobiiglasses.stop_streaming()
def generate_message(ts, gaze3, gaze_mapped, pd, gaze_screen, pc_left, pc_right):
msg = 'E;1;EyeTrack;;;;;EyeTrackerSample;'
......@@ -226,6 +254,7 @@ def generate_message(ts, gaze3, gaze_mapped, pd, gaze_screen, pc_left, pc_right)
msg += str(pc_right[2]) + '\r\n'
msg = msg.encode('utf-8')
return msg
def get_hom(result, fix):
......@@ -245,5 +274,11 @@ def get_hom(result, fix):
return H
def handler(signal_received, frame):
tobiiglasses.stop_streaming()
print("SIGINT or CTRL-C detected. Exiting...")
exit(0)
if __name__ == "__main__":
signal(SIGINT, handler)
main()
......@@ -22,11 +22,11 @@ def main():
start = time.time()
elapsed = 0
while elapsed < 2:
data = tobiiglasses.get_data()['left_eye']
data = tobiiglasses.get_data()
if 'gp3' in data.keys():
data = data['gp3']
print(data)
# time.sleep(0.02)
time.sleep(0.01)
elapsed = time.time() - start
tobiiglasses.stop_streaming()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment