diff --git a/pupil_src/player/player_methods.py b/pupil_src/player/player_methods.py index d3b4380da3..7c76a2c291 100644 --- a/pupil_src/player/player_methods.py +++ b/pupil_src/player/player_methods.py @@ -84,6 +84,8 @@ def update_recording_to_recent(rec_dir): update_recording_v082_to_v083(rec_dir) if rec_version < VersionFormat('0.8.6'): update_recording_v083_to_v086(rec_dir) + if rec_version < VersionFormat('0.8.7'): + update_recording_v086_to_v087(rec_dir) # How to extend: # if rec_version < VersionFormat('FUTURE FORMAT'): # update_recording_v081_to_FUTURE(rec_dir) @@ -171,6 +173,36 @@ def update_recording_v083_to_v086(rec_dir): csv_utils.write_key_value_file(csvfile,meta_info) +def update_recording_v086_to_v087(rec_dir): + logger.info("Updating recording from v0.8.6 format to v0.8.7 format") + pupil_data = load_object(os.path.join(rec_dir, "pupil_data")) + meta_info_path = os.path.join(rec_dir,"info.csv") + + + def _clamp_norm_point(pos): + '''realisitic numbers for norm pos should be in this range. + Grossly bigger or smaller numbers are results bad exrapolation + and can cause overflow erorr when denormalized and cast as int32. + ''' + return min(100,max(-100,pos[0])),min(100,max(-100,pos[1])) + + for g in pupil_data['gaze_positions']: + if 'topic' not in g: + #we missed this in one gaze mapper + g['topic'] = topic + g['norm_pos'] = _clamp_norm_point(g['norm_pos']) + + save_object(pupil_data,os.path.join(rec_dir, "pupil_data")) + + with open(meta_info_path) as csvfile: + meta_info = csv_utils.read_key_value_file(csvfile) + meta_info['Capture Software Version'] = 'v0.8.7' + + with open(meta_info_path,'w') as csvfile: + csv_utils.write_key_value_file(csvfile,meta_info) + + + def update_recording_v073_to_v074(rec_dir): logger.info("Updating recording from v0.7x format to v0.7.4 format") diff --git a/pupil_src/shared_modules/calibration_routines/gaze_mappers.py b/pupil_src/shared_modules/calibration_routines/gaze_mappers.py index 44df6580ac..f906970ccf 100644 --- a/pupil_src/shared_modules/calibration_routines/gaze_mappers.py +++ b/pupil_src/shared_modules/calibration_routines/gaze_mappers.py @@ -23,6 +23,12 @@ from visualizer_calibration import * +def _clamp_norm_point(pos): + '''realisitic numbers for norm pos should be in this range. + Grossly bigger or smaller numbers are results bad exrapolation + and can cause overflow erorr when denormalized and cast as int32. + ''' + return min(100,max(-100,pos[0])),min(100,max(-100,pos[1])) class Gaze_Mapping_Plugin(Plugin): '''base class for all gaze mapping routines''' @@ -242,6 +248,7 @@ def _map_monocular(self,p): image_point, _ = cv2.projectPoints( np.array([gaze_point]) , self.rotation_vector, self.translation_vector , self.camera_matrix , self.dist_coefs ) image_point = image_point.reshape(-1,2) image_point = normalize( image_point[0], self.world_frame_size , flip_y = True) + image_point = _clamp_norm_point(image_point) eye_center = self.toWorld(p['sphere']['center']) gaze_3d = self.toWorld(gaze_point) @@ -353,7 +360,7 @@ def _map_monocular(self,p): image_point, _ = cv2.projectPoints( np.array([gaze_point]) , self.rotation_vectors[p_id], self.translation_vectors[p_id] , self.camera_matrix , self.dist_coefs ) image_point = image_point.reshape(-1,2) image_point = normalize( image_point[0], self.world_frame_size , flip_y = True) - + image_point = _clamp_norm_point(image_point) if p_id == 0: eye_center = self.eye0_to_World(p['sphere']['center']) gaze_3d = self.eye0_to_World(gaze_point) @@ -426,6 +433,7 @@ def _map_binocular(self, p0, p1): image_point, _ = cv2.projectPoints( np.array([nearest_intersection_point]) , np.array([0.0,0.0,0.0]) , np.array([0.0,0.0,0.0]) , self.camera_matrix , self.dist_coefs ) image_point = image_point.reshape(-1,2) image_point = normalize( image_point[0], self.world_frame_size , flip_y = True) + image_point = _clamp_norm_point(image_point) if self.visualizer.window: