diff --git a/code/parallax_analysis.py b/code/parallax_analysis.py index 2812aa3..7d7a2e5 100644 --- a/code/parallax_analysis.py +++ b/code/parallax_analysis.py @@ -1,7 +1,7 @@ from __future__ import division import os, sys -import seaborn +# import seaborn from pylab import rcParams import cv2 @@ -203,11 +203,11 @@ class Parallax2Dto3DMapping(Experiment): aae_3ds_aae.append((AAE, STD)) aae_3ds_phe.append((PHE, PHE_STD)) + # results only contains AAE results.append([np.mean(np.array(aae_2ds_aae)[:,0]), np.mean(np.array(aae_3ds_aae)[:,0]), np.mean(np.array(aae_3D3Ds)[:,0])]) results_std.append([np.std(np.array(aae_2ds_aae)[:,0]), np.std(np.array(aae_3ds_aae)[:,0]), np.std(np.array(aae_3D3Ds)[:,0])]) - ###################################################################################################### # plot code based on EffectNumberofClusters.py mean2D2D = [res[0] for res in results] @@ -272,6 +272,7 @@ class Parallax2Dto3DMapping(Experiment): plt.subplots_adjust(left=left, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace) plt.show() ###################################################################################################### + self.sim = sim class Parallax3Dto3DMapping(Experiment): # GT pupil pose instead of estimating the pose def __run__(self): diff --git a/code/recording_experiment.py b/code/recording_experiment.py index 2807e10..e5fb95b 100644 --- a/code/recording_experiment.py +++ b/code/recording_experiment.py @@ -8,10 +8,11 @@ from time import time from geom import getSphericalCoords, getAngularDiff from recording.tracker import Marker -try: - from visual import vector as v -except ImportError: - from vector import Vector as v +# try: +# from visual import vector as v +# except ImportError: +# from vector import Vector as v +from vector import Vector as v DATA_DIR = './recording/data/' # DATA_DIR = '.\\recording\\data\\' diff --git a/code/sim.py b/code/sim.py index 9ac7661..adad69a 100644 --- a/code/sim.py +++ b/code/sim.py @@ -9,19 +9,25 @@ simply run the experiment with no visualization to get the data. However, you can as well visualize the environment after the simulation environment is set up and you ran the experiment. in order to do so, after you have a GazeSimulation object, simply call visualize() method on it. +(notice that you need to disable plotting code so you can visualize and manipulate +the visualization otherwise after closing the plots the app stops) ''' try: import visual as vs - from visual import vector as v + from visual import vector as vv except ImportError: - from vector import Vector as vector + from vector import Vector as vv +# from vector import Vector as vector + pass +from vector import Vector as v + import numpy as np import cv2, cv from geom import * ## Uncomment the following import if you want visualization -# from svis import Visualizable +from svis import Visualizable # 2D to 2D calibration method from the pupil project from pupil.calibrate import get_map_from_cloud @@ -31,8 +37,8 @@ from pupil.calibrate import get_map_from_cloud point_scale_factor = 10 ## Uncomment the following if you want visualization (and comment the line after) -# class GazeSimulation(Visualizable): -class GazeSimulation: +class GazeSimulation(Visualizable): +# class GazeSimulation: _log = True def log(self, msg): if self._log: print msg @@ -531,6 +537,8 @@ class GazeSimulation: calibration = False # display_test_point_rays = False # display_active_gaze_point = False + display_calibration_point_rays = True + display_test_point_rays = True rays = [] def draw(self): @@ -540,22 +548,26 @@ class GazeSimulation: ''' from util import drawAxes, drawLine from svis import drawCameraFrame + + # converts a vector object into a visual vector object + v_to_vv = lambda vec: vv(vec.x, vec.y, vec.z) + ## World Axes - drawAxes(None, vs.color.white, 13, (0, 0, 0)) + # drawAxes(None, vs.color.white, 13, (0, 0, 0)) ## Eyeball component (outer sphere) - eye_outer = vs.sphere(pos=self.sclera_pos, + eye_outer = vs.sphere(pos=v_to_vv(self.sclera_pos), radius=self.sclera_radius, color=vs.color.red) ## Eyeball component (inner sphere) - eye_inner = vs.sphere(pos=self.cornea_pos, + eye_inner = vs.sphere(pos=v_to_vv(self.cornea_pos), radius = self.cornea_radius, color=vs.color.white) self.recomputeEyeInner() - eye_inner.pos = self.cornea_pos + eye_inner.pos = v_to_vv(self.cornea_pos) ## Pupil position if self.display_pupil_position: - vs.points(pos=[self.pupil_position], size=5, color=vs.color.black) + vs.points(pos=[v_to_vv(self.pupil_position)], size=5, color=vs.color.black) ## calibration points if self.display_calibration_points: vs.points(pos=self.calibration_points, size=10, color=vs.color.yellow) @@ -572,18 +584,18 @@ class GazeSimulation: if self.display_calibration_point_rays: # Cast rays from scene camera towards calibration points for point in self.calibration_points: - diff = vs.vector(point) - vs.vector(self.scene_camera.t) - drawLine(None, vs.vector(self.scene_camera.t), diff.mag, diff.norm()) + diff = vv(point) - vv(self.scene_camera.t) + drawLine(None, vv(self.scene_camera.t), diff.mag, diff.norm()) # Display rays from scene camera towards test points if self.display_test_point_rays: # Cast rays from scene camera towards calibration points for point in self.test_points: - diff = vs.vector(point) - vs.vector(self.scene_camera.t) - drawLine(None, vs.vector(self.scene_camera.t), diff.mag, diff.norm()) + diff = vv(point) - vv(self.scene_camera.t) + drawLine(None, vv(self.scene_camera.t), diff.mag, diff.norm()) # active gaze point if self.display_active_gaze_point and self.active_gaze_point: - vs.points(pos=[self.active_gaze_point], size=10, color=vs.color.red) + vs.points(pos=[v_to_vv(self.active_gaze_point)], size=10, color=vs.color.red) if self.tr_target_projections_3d: vs.points(pos=self.tr_target_projections_3d, size=7, color=vs.color.red) diff --git a/code/svis.py b/code/svis.py index 0eeb854..b28f5ce 100644 --- a/code/svis.py +++ b/code/svis.py @@ -3,24 +3,29 @@ This is the visualization backend for bare_sim module ''' try: import visual as vs - from visual import vector as v + from visual import vector as vv except ImportError: - from vector import Vector as v + from vector import Vector as vv +# from vector import Vector as vector + pass +from vector import Vector as v from geom import Camera from util import drawAxes +# converts a vector object into a visual vector object +v_to_vv = lambda vec: vv(vec.x, vec.y, vec.z) def drawCameraFrame(cam): # create frame and draw its contents c = v(cam.t) - cam.center = vs.sphere(pos=c, + cam.center = vs.sphere(pos=v_to_vv(c), radius=Camera.default_radius, color=vs.color.green) - cam.dir = vs.arrow(pos=c, - axis=v(cam.direction) * cam.f, + cam.dir = vs.arrow(pos=v_to_vv(c), + axis=v_to_vv(v(cam.direction)) * cam.f, shaftwidth=1.0) # TODO: check for orientation of the camera, rotate plane accordingly - cam.img_plane = vs.box(pos=c + cam.dir.axis, + cam.img_plane = vs.box(pos=v_to_vv(c) + v_to_vv(cam.dir.axis), length=cam.image_width, width=0.5, height=cam.image_width, diff --git a/code/util.py b/code/util.py index 848d09d..5f9f0c4 100644 --- a/code/util.py +++ b/code/util.py @@ -1,8 +1,11 @@ try: import visual as vs - from visual import vector as v + from visual import vector as vv except ImportError: - from vector import Vector as vector + from vector import Vector as vv +# from vector import Vector as vector + pass +from vector import Vector as v import wx @@ -28,7 +31,7 @@ def drawLine(frame, position, length, direction, color = vs.color.white): ''' return vs.curve( frame=frame, - pos=[v(position), v(position)+v(direction).norm()*length], + pos=[vv(position), vv(position)+vv(direction).norm()*length], color = color)