Skip to content

Commit

Permalink
clamping norm post for 3d mapper to some sane values fixing #533 .
Browse files Browse the repository at this point in the history
  • Loading branch information
mkassner committed Nov 30, 2016
1 parent 8ca7bae commit f6c12d7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pupil_src/player/player_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 9 additions & 1 deletion pupil_src/shared_modules/calibration_routines/gaze_mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f6c12d7

Please sign in to comment.