Skip to content

Commit

Permalink
implement confidence filtering in player.
Browse files Browse the repository at this point in the history
version bump and data format upgrade.
  • Loading branch information
mkassner committed Nov 2, 2016
1 parent 23fdcc7 commit 7f4deb2
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 7 deletions.
9 changes: 9 additions & 0 deletions pupil_src/player/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def get_dt():
g_pool.rec_dir = rec_dir
g_pool.rec_version = rec_version
g_pool.meta_info = meta_info
g_pool.min_data_confidence = session_settings.get('min_data_confidence',0.6)
g_pool.pupil_positions_by_frame = correlate_data(pupil_list,g_pool.timestamps)
g_pool.gaze_positions_by_frame = correlate_data(gaze_list,g_pool.timestamps)
g_pool.fixations_by_frame = [[] for x in g_pool.timestamps] #populated by the fixation detector plugin
Expand Down Expand Up @@ -268,6 +269,12 @@ def set_scale(new_scale):
g_pool.gui.scale = new_scale
g_pool.gui.collect_menus()

def set_data_confidence(new_confidence):
g_pool.min_data_confidence = new_confidence
notification = {'subject':'min_data_confidence_changed'}
notification['_notify_time_'] = time()+.8
g_pool.delayed_notifications[notification['subject']] = notification

def open_plugin(plugin):
if plugin == "Select to load":
return
Expand Down Expand Up @@ -303,6 +310,7 @@ def do_export(_):
g_pool.main_menu.append(ui.Slider('scale',g_pool.gui, setter=set_scale,step = .05,min=0.75,max=2.5,label='Interface Size'))
g_pool.main_menu.append(ui.Info_Text('Player Version: %s'%g_pool.version))
g_pool.main_menu.append(ui.Info_Text('Recording Version: %s'%rec_version))
g_pool.main_menu.append(ui.Slider('min_data_confidence',g_pool, setter=set_data_confidence,step=.05 ,min=0.0,max=1.0,label='Confidence threshold'))

selector_label = "Select to load"

Expand Down Expand Up @@ -464,6 +472,7 @@ def do_export(_):
glfwPollEvents()

session_settings['loaded_plugins'] = g_pool.plugins.get_initializers()
session_settings['min_data_confidence'] = g_pool.min_data_confidence
session_settings['gui_scale'] = g_pool.gui.scale
session_settings['ui_config'] = g_pool.gui.configuration
session_settings['window_size'] = glfwGetWindowSize(main_window)
Expand Down
22 changes: 22 additions & 0 deletions pupil_src/player/player_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def update_recording_to_recent(rec_dir):
update_recording_v074_to_v082(rec_dir)
if rec_version < VersionFormat('0.8.3'):
update_recording_v082_to_v083(rec_dir)
if rec_version < VersionFormat('0.8.6'):
update_recording_v083_to_v086(rec_dir)
# How to extend:
# if rec_version < VersionFormat('FUTURE FORMAT'):
# update_recording_v081_to_FUTURE(rec_dir)
Expand Down Expand Up @@ -150,6 +152,26 @@ def update_recording_v082_to_v083(rec_dir):
csv_utils.write_key_value_file(csvfile,meta_info)


def update_recording_v083_to_v086(rec_dir):
logger.info("Updating recording from v0.8.3 format to v0.8.6 format")
pupil_data = load_object(os.path.join(rec_dir, "pupil_data"))
meta_info_path = os.path.join(rec_dir,"info.csv")

for topic in pupil_data.keys():
for d in pupil_data[topic]:
d['topic'] = topic

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.6'

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")
pupil_data = load_object(os.path.join(rec_dir, "pupil_data"))
Expand Down
2 changes: 1 addition & 1 deletion pupil_src/player/vis_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def update(self,frame,events):
else:
thickness = self.thickness

pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[])]
pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[]) if pt['confidence']>=self.g_pool.min_data_confidence]
for pt in pts:
transparent_circle(frame.img, pt, radius=self.radius, color=(self.b, self.g, self.r, self.a), thickness=thickness)

Expand Down
2 changes: 1 addition & 1 deletion pupil_src/player/vis_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, g_pool,inner=20,outer=100,color=(1.,0.0,0.0,1.0),thickness=1)
self.thickness = thickness

def update(self,frame,events):
pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[])]
pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[]) if pt['confidence']>=self.g_pool.min_data_confidence]
bgra = (self.b*255,self.g*255,self.r*255,self.a*255)
for pt in pts:
lines = np.array( [((pt[0]-self.inner,pt[1]),(pt[0]-self.outer,pt[1])),((pt[0]+self.inner,pt[1]),(pt[0]+self.outer,pt[1])) , ((pt[0],pt[1]-self.inner),(pt[0],pt[1]-self.outer)) , ((pt[0],pt[1]+self.inner),(pt[0],pt[1]+self.outer))],dtype=np.int32 )
Expand Down
2 changes: 1 addition & 1 deletion pupil_src/player/vis_light_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def update(self,frame,events):
falloff = self.falloff

img = frame.img
screen_gaze = [denormalize(g['norm_pos'],self.g_pool.capture.frame_size,flip_y=True) for g in events.get('gaze_positions',[])]
pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[]) if pt['confidence']>=self.g_pool.min_data_confidence]

overlay = np.ones(img.shape[:-1],dtype=img.dtype)

Expand Down
2 changes: 1 addition & 1 deletion pupil_src/player/vis_polyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, g_pool,color=(1.0,0.0,0.4,1.0),thickness=2):
self.thickness = thickness

def update(self,frame,events):
pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[])]
pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[]) if pt['confidence']>=self.g_pool.min_data_confidence]
bgra = (self.b*255,self.g*255,self.r*255,self.a*255)
if pts:
pts = np.array([pts],dtype=np.int32)
Expand Down
3 changes: 2 additions & 1 deletion pupil_src/shared_modules/offline_reference_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def generate_heatmap(self,section):
if c_e:
frame_idx+=section.start
for gp in self.gaze_on_srf_by_frame_idx(frame_idx,c_e['m_from_screen']):
all_gaze.append(gp['norm_pos'])
if gp['confidence']>=self.g_pool.min_data_confidence:
all_gaze.append(gp['norm_pos'])

if not all_gaze:
logger.warning("No gaze data on surface for heatmap found.")
Expand Down
5 changes: 4 additions & 1 deletion pupil_src/shared_modules/offline_surface_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,14 @@ def on_notify(self,notification):
if notification['subject'] == 'gaze_positions_changed':
logger.info('Gaze postions changed. Recalculating.')
self.recalculate()
if notification['subject'] == 'min_data_confidence_changed':
logger.info('Min_data_confidence changed. Recalculating.')
self.recalculate()
elif notification['subject'] == 'surfaces_changed':
logger.info('Surfaces changed. Recalculating.')
self.recalculate()
elif notification['subject'] == 'min_marker_perimeter_changed':
logger.info('Min marper perimeter adjusted. Re-detecting surfaces.')
logger.info('Min marker perimeter adjusted. Re-detecting surfaces.')
self.invalidate_surface_caches()
elif notification['subject'] is "should_export":
self.save_surface_statsics_to_file(notification['range'],notification['export_dir'])
Expand Down
2 changes: 1 addition & 1 deletion pupil_src/shared_modules/reference_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def map_datum_to_surface(d,m_from_screen):
mapped_pos = cv2.perspectiveTransform(pos , m_from_screen )
mapped_pos.shape = (2)
on_srf = bool((0 <= mapped_pos[0] <= 1) and (0 <= mapped_pos[1] <= 1))
return {'norm_pos':(mapped_pos[0],mapped_pos[1]),'on_srf':on_srf,'base_data':d }
return {'topic':d['topic']+"_on_surface",'norm_pos':(mapped_pos[0],mapped_pos[1]),'confidence':d['confidence'],'on_srf':on_srf,'base_data':d }

def map_data_to_surface(self,data,m_from_screen):
return [self.map_datum_to_surface(d,m_from_screen) for d in data]
Expand Down

0 comments on commit 7f4deb2

Please sign in to comment.