def __init__(self,g_pool,atb_pos=(320,220)): super(Marker_Detector, self).__init__() self.g_pool = g_pool self.order = .2 # all markers that are detected in the most recent frame self.markers = [] # all registered surfaces self.surface_definitions = Persistent_Dict(os.path.join(g_pool.user_dir,'surface_definitions') ) self.surfaces = [Reference_Surface(saved_definition=d) for d in self.load('realtime_square_marker_surfaces',[]) if isinstance(d,dict)] # edit surfaces self.surface_edit_mode = c_bool(0) self.edit_surfaces = [] #detector vars self.robust_detection = c_bool(1) self.aperture = c_int(11) self.min_marker_perimeter = 80 #debug vars self.draw_markers = c_bool(0) self.show_surface_idx = c_int(0) self.recent_pupil_positions = [] self.img_shape = None atb_label = "marker detection" self._bar = atb.Bar(name =self.__class__.__name__, label=atb_label, help="marker detection parameters", color=(50, 150, 50), alpha=100, text='light', position=atb_pos,refresh=.3, size=(300, 300)) self.update_bar_markers()
def load_surface_definitions_from_file(self): # all registered surfaces self.surface_definitions = Persistent_Dict( os.path.join(self.g_pool.user_dir, 'surface_definitions')) self.surfaces = [ Reference_Surface(saved_definition=d) for d in self.surface_definitions.get( 'realtime_square_marker_surfaces', []) if isinstance(d, dict) ]
def load_surface_definitions_from_file(self): # all registered surfaces self.surface_definitions = Persistent_Dict( os.path.join(self.g_pool.user_dir, "surface_definitions")) self.surfaces = [ Reference_Surface(self.g_pool, saved_definition=d) for d in self.surface_definitions.get( "realtime_square_marker_surfaces", []) ]
def __init__(self, g_pool, mode="Show markers and frames"): super(Marker_Detector, self).__init__(g_pool) self.order = .2 # all markers that are detected in the most recent frame self.markers = [] #load camera intrinsics try: K = np.load(os.path.join(self.g_pool.user_dir, 'camera_matrix.npy')) dist_coef = np.load( os.path.join(self.g_pool.user_dir, "dist_coefs.npy")) img_size = np.load( os.path.join(self.g_pool.user_dir, "camera_resolution.npy")) self.camera_intrinsics = K, dist_coefs, img_size except: self.camera_intrinsics = None # all registered surfaces self.surface_definitions = Persistent_Dict( os.path.join(g_pool.user_dir, 'surface_definitions')) self.surfaces = [ Reference_Surface(saved_definition=d) for d in self.surface_definitions.get( 'realtime_square_marker_surfaces', []) if isinstance(d, dict) ] # edit surfaces self.edit_surfaces = [] #plugin state self.mode = mode self.running = True self.robust_detection = 1 self.aperture = 11 self.min_marker_perimeter = 80 self.locate_3d = False #debug vars self.draw_markers = 0 self.show_surface_idx = 0 self.img_shape = None self.menu = None self.button = None self.add_button = None
def add_surface(self,_): self.surfaces.append(Reference_Surface()) self.update_gui_markers()
def add_surface(self, _): surf = Reference_Surface(self.g_pool) surf.on_finish_define = self.save_surface_definitions_to_file self.surfaces.append(surf) self.update_gui_markers()
def __init__(self, g_pool, mode="Show markers and frames", min_marker_perimeter=40): super(Marker_Detector, self).__init__(g_pool) self.order = .2 # all markers that are detected in the most recent frame self.markers = [] #load camera intrinsics try: camera_calibration = load_object( os.path.join(self.g_pool.user_dir, 'camera_calibration')) except: self.camera_intrinsics = None else: same_name = camera_calibration[ 'camera_name'] == self.g_pool.capture.name same_resolution = camera_calibration[ 'resolution'] == self.g_pool.capture.frame_size if same_name and same_resolution: logger.info( 'Loaded camera calibration. 3D marker tracking enabled.') K = camera_calibration['camera_matrix'] dist_coefs = camera_calibration['dist_coefs'] resolution = camera_calibration['resolution'] self.camera_intrinsics = K, dist_coefs, resolution else: logger.info( 'Loaded camera calibration but camera name and/or resolution has changed. Please re-calibrate.' ) self.camera_intrinsics = None # all registered surfaces self.surface_definitions = Persistent_Dict( os.path.join(g_pool.user_dir, 'surface_definitions')) self.surfaces = [ Reference_Surface(saved_definition=d) for d in self.surface_definitions.get( 'realtime_square_marker_surfaces', []) if isinstance(d, dict) ] # edit surfaces self.edit_surfaces = [] #plugin state self.mode = mode self.running = True self.robust_detection = 1 self.aperture = 11 self.min_marker_perimeter = min_marker_perimeter self.locate_3d = False #debug vars self.draw_markers = 0 self.show_surface_idx = 0 self.img_shape = None self.menu = None self.button = None self.add_button = None
def __init__(self, g_pool, atb_pos=(320, 220)): super(Marker_Detector, self).__init__() self.g_pool = g_pool self.order = .2 # all markers that are detected in the most recent frame self.markers = [] # all registered surfaces if g_pool.app == 'capture': self.surface_definitions = shelve.open(os.path.join( g_pool.user_dir, 'surface_definitions'), protocol=2) self.surfaces = [ Reference_Surface(saved_definition=d) for d in self.load('realtime_square_marker_surfaces', []) if isinstance(d, dict) ] elif g_pool.app == 'player': #in player we load from the rec_dir: but we have a couple options: self.surface_definitions = shelve.open(os.path.join( g_pool.rec_dir, 'surface_definitions'), protocol=2) if self.load('offline_square_marker_surfaces', []) != []: logger.debug( "Found ref surfaces defined or copied in previous session." ) self.surfaces = [ Reference_Surface(saved_definition=d) for d in self.load('offline_square_marker_surfaces', []) if isinstance(d, dict) ] elif self.load('offline_square_marker_surfaces', []) != []: logger.debug( "Did not find ref surfaces def created or used by the user in player from earlier session. Loading surfaces defined during capture." ) self.surfaces = [ Reference_Surface(saved_definition=d) for d in self.load('realtime_square_marker_surfaces', []) if isinstance(d, dict) ] else: logger.debug("No surface defs found. Please define using GUI.") self.surfaces = [] # edit surfaces self.surface_edit_mode = c_bool(0) self.edit_surfaces = [] #detector vars self.robust_detection = c_bool(1) self.aperture = c_int(11) self.min_marker_perimeter = 80 #debug vars self.draw_markers = c_bool(0) self.show_surface_idx = c_int(0) self.recent_pupil_positions = [] self.img_shape = None #multi monitor setup self.window_should_open = False self.window_should_close = False self._window = None self.fullscreen = c_bool(0) self.monitor_idx = c_int(0) monitor_handles = glfwGetMonitors() self.monitor_names = [glfwGetMonitorName(m) for m in monitor_handles] monitor_enum = atb.enum( "Monitor", dict(((key, val) for val, key in enumerate(self.monitor_names)))) #primary_monitor = glfwGetPrimaryMonitor() atb_label = "marker detection" self._bar = atb.Bar(name=self.__class__.__name__, label=atb_label, help="marker detection parameters", color=(50, 50, 50), alpha=100, text='light', position=atb_pos, refresh=.3, size=(300, 100)) self._bar.add_var( "monitor", self.monitor_idx, vtype=monitor_enum, group="Window", ) self._bar.add_var("fullscreen", self.fullscreen, group="Window") self._bar.add_button(" open Window ", self.do_open, key='m', group="Window") self._bar.add_var("surface to show", self.show_surface_idx, step=1, min=0, group="Window") self._bar.add_var('robust_detection', self.robust_detection, group="Detector") self._bar.add_var("draw markers", self.draw_markers, group="Detector") self._bar.add_button('close', self.unset_alive) atb_pos = atb_pos[0], atb_pos[1] + 110 self._bar_markers = atb.Bar(name=self.__class__.__name__ + 'markers', label='registered surfaces', help="list of registered ref surfaces", color=(50, 100, 50), alpha=100, text='light', position=atb_pos, refresh=.3, size=(300, 120)) self.update_bar_markers()
def add_surface(self): self.surfaces.append(Reference_Surface()) self.update_bar_markers()