Last active
August 29, 2015 14:02
-
-
Save roberto-arista/0b450eb1ec845f35a60a to your computer and use it in GitHub Desktop.
A Python/Drawbot script able to visualize gaze_position.npy by Pupil Capture eye-tracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################ | |
# Gaze positions visualization # | |
################################ | |
### Modules | |
import numpy | |
import sys | |
from operator import itemgetter | |
### Functions | |
def drawOvals(points, diameter): | |
for point in points: | |
x = point[0] | |
y = point[1] | |
oval(x-diameter/2, y-diameter/2, diameter, diameter) | |
def drawLines(points): | |
bezierPath = BezierPath() | |
bezierPath.moveTo(points[0]) | |
for each_point in points[1:]: | |
bezierPath.lineTo(each_point) | |
drawPath(bezierPath) | |
def sliceArrayBySeconds(sequence, minimum, maximum): | |
sliced_sequence = [x for x in sequence if minimum <= x[1] <= maximum] | |
return sliced_sequence | |
### Variables | |
input_path = 'gaze_positions.npy' | |
diameter = 10 | |
minimum_time = 30 | |
maximum_time = 40 | |
### Instructions | |
# Reading numpy data | |
data = numpy.load(input_path) | |
# Converting to float and selecting coordinates | |
points_coordinates_percentage = [] | |
time_stamps = [] | |
for d in data: | |
points_coordinates_percentage.append([float(x) for x in d[:2]]) | |
time_stamps.append(float(d[4])) | |
# Adjusting time stamps | |
lower_time_stamp = min(time_stamps) | |
for i, each_time_stamp in enumerate(time_stamps): | |
time_stamps[i] = each_time_stamp - lower_time_stamp | |
# Adjusting to monitor dimension | |
points_coordinate_pixel = [] | |
for each_point in points_coordinates_percentage: | |
pixel_point = (each_point[0]*1280, each_point[1]*720) | |
points_coordinate_pixel.append(pixel_point) | |
# Zipping coordinates and timestamps in a dict | |
points_and_timestamps = dict(zip(points_coordinate_pixel, time_stamps)) | |
# Ordering timeStamps | |
points_and_timestamps = sorted(points_and_timestamps.items(), key=itemgetter(1), reverse = False) | |
sliced_points_and_timestamps = sliceArrayBySeconds(points_and_timestamps, minimum_time, maximum_time) | |
# Canvas dimension | |
size(1280, 720) | |
# Graphics qualities | |
fill(0) | |
stroke(None) | |
# drawing dots | |
coordinates = [x[0] for x in sliced_points_and_timestamps] | |
drawOvals(coordinates, diameter) | |
# drawing lines | |
stroke(0) | |
fill(None) | |
drawLines(coordinates) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment