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

updates

parent 7e1179fc
Branches
No related tags found
No related merge requests found
......@@ -32,14 +32,14 @@ for i in range(3):
centers.append((int(x),int(y)))
x = 320
y = 240
img = cv2.resize(blank_image, (640,480))
cv2.circle(img, (int(x), int(y)), 2, (0,0,255), 20)
cv2.circle(img, (int(x+50), int(y)), 2, (0,0,255), 20)
cv2.circle(img, (int(x), int(y+50)), 2, (0,0,255), 20)
cv2.imshow("screen", img)
# x = 320
# y = 240
# img = cv2.resize(blank_image, (640,480))
# cv2.circle(img, (int(x), int(y)), 2, (0,0,255), 20)
# cv2.circle(img, (int(x+50), int(y)), 2, (0,0,255), 20)
# cv2.circle(img, (int(x), int(y+50)), 2, (0,0,255), 20)
cv2.imshow("screen", blank_image)
# print(centers)
if cv2.waitKey(0) & 0xFF == ord('q'):
......
......@@ -49,6 +49,26 @@ def get_center(img, detector, tag_id):
print("could not find tag with id:", tag_id)
sys.exit(1)
def get_centers(img, detector):
detections = detector.detect(img)
centers = []
for detection in detections:
centers.append(detection.center)
return centers
def get_closest(gaze_mapped, err_centers):
min_err = 10000000
min_center = None
for center in err_centers:
if np.sqrt(np.sum((gaze_mapped[:2] - center)**2)) < min_err:
min_err = np.sqrt(np.sum((gaze_mapped[:2] - center)**2))
min_center = center
return min_center
ip = '192.168.71.50'
tobiiglasses = TobiiGlassesController(ip, video_scene=True)
project_id = tobiiglasses.create_project("Test live_scene_and_gaze.py")
......@@ -105,7 +125,7 @@ if len(back_detections) < num_apriltags:
tobiiglasses.stop_streaming()
sys.exit(1)
screen1 = cv2.imread('screen1_circles.jpg')
screen1 = cv2.imread('error_screen.jpg')
screen1 = cv2.resize(screen1, (640,480))
screen2 = cv2.imread('screen2.jpg')
screen2 = cv2.resize(screen2, (640,480))
......@@ -120,9 +140,9 @@ fix_s1 = get_dict_from_image(s1_grey, detector)
fix_s2 = get_dict_from_image(s2_grey, detector)
fix_s3 = get_dict_from_image(s3_grey, detector)
# err_tag_id = 8
# detector_2 = Detector(families="tag36h11", nthreads=1, quad_decimate=1.0)
# err_center = get_center(s1_grey, detector_2, err_tag_id)
err_tag_id = [i for i in range(9)]
detector_2 = Detector(families="tag36h11", nthreads=1, quad_decimate=1.0)
err_centers = get_centers(s1_grey, detector_2)
fix = {}
for detection in back_detections:
......@@ -202,8 +222,12 @@ while True:
gaze_mapped_s1 = np.dot(H1, gaze_mapped)
gaze_mapped_s1 = gaze_mapped_s1/gaze_mapped_s1[2]
cv2.circle(s1_copy, (int(gaze_mapped_s1[0]), int(gaze_mapped_s1[1])), 2, (255,0,0), 10)
# vec = (gaze_mapped_s1[:2] - err_center)
# err.append(vec)
# err_center = get_closest(gaze_mapped_s1, err_centers)
# if err_center is not None:
# # vec = (gaze_mapped_s1[:2] - err_center)
vec = gaze_mapped_s1[:2]
err.append(vec)
elif gaze_mapped_back[0] > s2_min and gaze_mapped_back[0] < s2_max and gaze_mapped_back[1] < 240:
......@@ -238,11 +262,12 @@ while True:
elif pd_left == -1 or pd_right == -1:
num_blinks += 1
# dir_name = "error_data/Screen1/multiple/pos" + str(err_tag_id)
# if not os.path.exists(dir_name):
# os.makedirs(dir_name)
dir_name = "error_data/Screen1/multiple/gazedata"
if not os.path.exists(dir_name):
os.makedirs(dir_name)
np.save(dir_name + "/data1", err)
# np.save(dir_name + "/direct_gaze_1", err)
# np.save(dir_name + "/looking_left_corner_1", err)
# np.save(dir_name + "/looking_right_corner_1", err)
......
......@@ -52,9 +52,23 @@ def get_center(img, detector, tag_id):
def IVT_filter(mapped_gaze_2d, last_mapped_gaze, ts, last_ts):
velocity_threshold = 100
# print("vel before: ", np.sqrt(np.sum((mapped_gaze_2d-last_mapped_gaze)**2)/(ts - last_ts) * 1e6))
mapped_gaze = mapped_gaze_2d.copy()
last_mapped = last_mapped_gaze.copy()
mapped_gaze[0] = (mapped_gaze_2d[0] / 640.0) * 450
last_mapped[0] = (last_mapped_gaze[0] / 640.0) * 450
mapped_gaze[1] = (mapped_gaze_2d[1] / 480.0) * 300
last_mapped[1] = (last_mapped_gaze[1] / 480.0) * 300
# print("vel after: ", np.sqrt(np.sum((mapped_gaze_2d-last_mapped_gaze)**2)/(ts - last_ts) * 1e6))
if ts - last_ts < 1e2:
return False
vel = np.sqrt(np.sum((mapped_gaze_2d-last_mapped_gaze)**2)/(ts - last_ts) * 1e6)
vel = np.sqrt(np.sum((mapped_gaze-last_mapped)**2)/(ts - last_ts) * 1e6)
# print(vel)
if vel <= velocity_threshold:
return True
......@@ -80,6 +94,7 @@ project_id = tobiiglasses.create_project("Test live_scene_and_gaze.py")
participant_id = tobiiglasses.create_participant(project_id, "participant_test")
calibration_id = tobiiglasses.create_calibration(project_id, participant_id)
print(tobiiglasses.get_battery_status())
input("Put the calibration marker in front of the user, then press enter to calibrate")
tobiiglasses.start_calibration(calibration_id)
......@@ -130,7 +145,7 @@ if len(back_detections) < num_apriltags:
tobiiglasses.stop_streaming()
sys.exit(1)
screen1 = cv2.imread('screen1.jpg')
screen1 = cv2.imread('error_screen.jpg')
screen1 = cv2.resize(screen1, (640,480))
screen2 = cv2.imread('screen2.jpg')
screen2 = cv2.resize(screen2, (640,480))
......@@ -245,7 +260,7 @@ while True:
gaze_mapped_s1 = np.dot(H1, gaze_mapped)
gaze_mapped_s1 = gaze_mapped_s1/gaze_mapped_s1[2]
if last_mapped_gaze is not None:
fixation_bool = IVT_filter(gaze_mapped_s1[:2], last_mapped_gaze, curr_ts, last_ts)
fixation_bool = IVT_filter(gaze_mapped_s1[:2], last_mapped_gaze[:2], curr_ts, last_ts)
last_mapped_gaze = gaze_mapped_s1
last_ts = curr_ts
if fixation_bool:
......
......@@ -2,16 +2,8 @@ import numpy as np
import matplotlib.pyplot as plt
max_length = 300
# data = np.load("time_data.npy")
# plt.figure()
# plt.plot(data[1:])
# plt.show()
# data = data[1:]
# print(data.sum()/len(data))
def avg(data, i, j, n):
# print(data)
......@@ -36,85 +28,136 @@ def remove_outliers(data):
return ret_data
file_names = ["direct_gaze_1", "looking_left_corner_1", "looking_right_corner_1", "moving_head_1"]
legend_list = ['pos' + str(i) for i in range(9)]
for name in file_names:
average_x = 0
average_y = 0
for i in range(9):
base_dir = "error_data/Screen1/multiple/pos"
tag_id = i
base_dir += str(tag_id) + '/'
data = np.load(base_dir + name + ".npy")
data_ = remove_outliers(data)
x_data = data_[0]
y_data = data_[1]
x_length = min(len(x_data), max_length)
y_length = min(len(y_data), max_length)
x_time = np.zeros((x_length, 1))
y_time = np.zeros((y_length, 1))
plot_data_x = np.zeros((x_length, 1))
plot_data_y = np.zeros((y_length, 1))
for j in range(x_length):
x_time[j] = j / 30.0
plot_data_x[j] = x_data[j] * 100 / 640
data = np.load("error_data/Screen1/multiple/allpos/direct_gaze_1.npy")
data = remove_outliers(data)
max_length = 900
x_time = np.zeros((max_length,))
y_time = np.zeros((max_length,))
for j in range(max_length):
x_time[j] = j / 30.0
for j in range(max_length):
y_time[j] = j / 30.0
x_data = np.array(data[0][:max_length]) * 100 / 640.0
y_data = np.array(data[1][:max_length]) * 100 / 480.0
x_mean = x_data.mean()
y_mean = y_data.mean()
plt.figure(0)
plt.plot(x_time, x_data)
plt.plot(x_time, [x_mean] * max_length, linewidth=3, color='black')
plt.title("Error in mapping x coordinate")
plt.ylabel("Error in gaze x coordinate (percentage)")
plt.xlabel("Time (s)")
plt.figure(1)
plt.plot(y_time, y_data)
plt.plot(y_time, [y_mean] * max_length, linewidth=3, color='black')
plt.title("Error in mapping y coordinate")
plt.ylabel("Error in gaze y coordinate (percentage)")
plt.xlabel("Time (s)")
plt.show()
# max_length = 300
# # data = np.load("time_data.npy")
# # plt.figure()
# # plt.plot(data[1:])
# # plt.show()
# # data = data[1:]
# # print(data.sum()/len(data))
# file_names = ["direct_gaze_1", "looking_left_corner_1", "looking_right_corner_1", "moving_head_1"]
# legend_list = ['pos' + str(i) for i in range(9)]
# for name in file_names:
# average_x = 0
# average_y = 0
# for i in range(9):
# base_dir = "error_data/Screen1/multiple/pos"
# tag_id = i
# base_dir += str(tag_id) + '/'
# data = np.load(base_dir + name + ".npy")
# data_ = remove_outliers(data)
# x_data = data_[0]
# y_data = data_[1]
# x_length = min(len(x_data), max_length)
# y_length = min(len(y_data), max_length)
# x_time = np.zeros((x_length, 1))
# y_time = np.zeros((y_length, 1))
# plot_data_x = np.zeros((x_length, 1))
# plot_data_y = np.zeros((y_length, 1))
# for j in range(x_length):
# x_time[j] = j / 30.0
# plot_data_x[j] = x_data[j] * 100 / 640
for j in range(y_length):
y_time[j] = j / 30.0
plot_data_y[j] = y_data[j] * 100 / 640
# for j in range(y_length):
# y_time[j] = j / 30.0
# plot_data_y[j] = y_data[j] * 100 / 640
average_x += plot_data_x.sum() / x_length
average_y += plot_data_y.sum() / y_length
# average_x += plot_data_x.sum() / x_length
# average_y += plot_data_y.sum() / y_length
plt.figure(0)
plt.plot(x_time, plot_data_x)
# plt.figure(0)
# plt.plot(x_time, plot_data_x)
plt.figure(1)
plt.plot(y_time, plot_data_y)
# plt.figure(1)
# plt.plot(y_time, plot_data_y)
# plt.figure(2)
# plt.plot(data[:max_length,0])
# # plt.figure(2)
# # plt.plot(data[:max_length,0])
# plt.figure(3)
# plt.plot(data[:max_length,1])
# # plt.figure(3)
# # plt.plot(data[:max_length,1])
average_x /= 9
average_y /= 9
plt.figure(0)
plt.plot(x_time, [average_x] * x_length, linewidth=3, color='black')
plt.ylabel("Gaze error x")
plt.xlabel("time (s)")
plt.title(name)
plt.legend(legend_list)
plt.figure(1)
plt.plot(y_time, [average_y] * y_length, linewidth=3, color='black')
plt.ylabel("Gaze error y")
plt.xlabel("time (s)")
plt.title(name)
plt.legend(legend_list)
# plt.figure(2)
# # plt.plot(x_time, [average_x] * x_length, linewidth=3, color='black')
# plt.ylabel("Gaze error x")
# plt.xlabel("time (s)")
# plt.title(name)
# # plt.legend(legend_list)
# plt.figure(3)
# # plt.plot(x_time, [average_x] * x_length, linewidth=3, color='black')
# plt.ylabel("Gaze error y")
# plt.xlabel("time (s)")
# plt.title(name)
# # plt.legend(legend_list)
plt.show()
# average_x /= 9
# average_y /= 9
# plt.figure(0)
# plt.plot(x_time, [average_x] * x_length, linewidth=3, color='black')
# plt.ylabel("Gaze error x")
# plt.xlabel("time (s)")
# plt.title(name)
# plt.legend(legend_list)
# plt.figure(1)
# plt.plot(y_time, [average_y] * y_length, linewidth=3, color='black')
# plt.ylabel("Gaze error y")
# plt.xlabel("time (s)")
# plt.title(name)
# plt.legend(legend_list)
# # plt.figure(2)
# # # plt.plot(x_time, [average_x] * x_length, linewidth=3, color='black')
# # plt.ylabel("Gaze error x")
# # plt.xlabel("time (s)")
# # plt.title(name)
# # # plt.legend(legend_list)
# # plt.figure(3)
# # # plt.plot(x_time, [average_x] * x_length, linewidth=3, color='black')
# # plt.ylabel("Gaze error y")
# # plt.xlabel("time (s)")
# # plt.title(name)
# # # plt.legend(legend_list)
# plt.show()
# for i in range(9):
# base_dir = "error_data/Screen1/multiple/pos"
......
......@@ -12,17 +12,17 @@ def main():
print("Please wait ...")
time.sleep(3.0)
# for i in range(1000):
# print("Head unit: %s" % tobiiglasses.get_data()['mems'])
# print("Left Eye: %s " % tobiiglasses.get_data()['left_eye'])
# print("Right Eye: %s " % tobiiglasses.get_data()['right_eye'])
# print("Gaze Position: %s " % tobiiglasses.get_data()['gp'])
# print("Gaze Position 3D: %s " % tobiiglasses.get_data()['gp3'])
# for i in range(10):
# print("Head unit: %s" % tobiiglasses.get_data()['mems'])
# print("Left Eye: %s " % tobiiglasses.get_data()['left_eye'])
# print("Right Eye: %s " % tobiiglasses.get_data()['right_eye'])
# print("Gaze Position: %s " % tobiiglasses.get_data()['gp'])
# print("Gaze Position 3D: %s " % tobiiglasses.get_data()['gp3'])
start = time.time()
elapsed = 0
while elapsed < 10:
data = tobiiglasses.get_data()['left_eye']['pd']
while elapsed < 5:
data = tobiiglasses.get_data()['gp3']
print(data)
# time.sleep(0.02)
elapsed = time.time() - start
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment