Esempio n. 1
0
    def __init__(self, g_pool, fullscreen=False):
        super().__init__(g_pool)
        self.collect_new = False
        self.calculated = False
        self.obj_grid = _gen_pattern_grid((4, 11))
        self.img_points = []
        self.obj_points = []
        self.count = 10
        self.display_grid = _make_grid()

        self._window = None

        self.menu = None
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.fullscreen = fullscreen
        self.monitor_idx = 0
        self.dist_mode = "Fisheye"

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align='center')

        self.undist_img = None
        self.show_undistortion = False
        self.show_undistortion_switch = None

        if hasattr(self.g_pool.capture, 'intrinsics') and self.g_pool.capture.intrinsics:
            logger.info('Click show undistortion to verify camera intrinsics calibration.')
            logger.info('Hint: Straight lines in the real world should be straigt in the image.')
        else:
            logger.info('No camera intrinsics calibration is currently set for this camera!')
Esempio n. 2
0
    def init_ui(self):
        self.add_menu()
        self.menu.label = 'Fixation Detector'

        for help_block in self.__doc__.split('\n\n'):
            help_str = help_block.replace('\n', ' ').replace('  ', '').strip()
            self.menu.append(ui.Info_Text(help_str))

        self.menu.append(
            ui.Slider('max_dispersion',
                      self,
                      min=0.01,
                      step=0.1,
                      max=5.,
                      label='Maximum Dispersion [degrees]'))
        self.menu.append(
            ui.Slider('min_duration',
                      self,
                      min=10,
                      step=10,
                      max=4000,
                      label='Minimum Duration [milliseconds]'))

        self.menu.append(
            ui.Slider('confidence_threshold',
                      self,
                      min=0.0,
                      max=1.0,
                      label='Confidence Threshold'))

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', ui.get_opensans_font_path())
        self.glfont.set_size(22)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
    def __init__(self,g_pool, menu_conf = {'collapsed':True},fullscreen = False):
        super(Camera_Intrinsics_Estimation, self).__init__(g_pool)
        self.collect_new = False
        self.calculated = False
        self.obj_grid = _gen_pattern_grid((4, 11))
        self.img_points = []
        self.obj_points = []
        self.count = 10
        self.img_shape = None

        self.display_grid = _make_grid()

        self._window = None

        self.menu = None
        self.menu_conf = menu_conf
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.fullscreen = fullscreen
        self.monitor_idx = 0


        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')
Esempio n. 4
0
    def __init__(self, g_pool, *args, **kwargs):
        super(PicoflexxCommon, self).__init__(g_pool)

        self.hue_near = kwargs.get('hue_near', 0.0)
        self.hue_far = kwargs.get('hue_far', 0.75)
        self.dist_near = kwargs.get('dist_near', 0.14)
        self.dist_far = kwargs.get('dist_far', 5.0)
        self.preview_true_depth = kwargs.get('preview_true_depth', False)
        self.preview_depth = kwargs.get('preview_depth', True)

        self._recent_depth_frame = None  # type: Optional[DepthFrame]
        self._recent_frame = None  # type: Optional[IRFrame]
        # capture doesn't provide this in g_pool like player does, main_window isn't present during export
        self._camera_render_size = glfw.glfwGetWindowSize(
            g_pool.main_window) if hasattr(g_pool, 'main_window') else None
        self.current_exposure = 0  # type: int

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_color_float((1.0, 1.0, 1.0, 0.8))
        self.glfont.set_align_string(v_align="center", h_align="top")

        self._colorbar_offs = (6, 30, 30, 30)
        self._colorbar_pos = [520, 12]
        self._colorbar_size = (300, 20)
        self._tex_id_color_bar = None
        self._current_opts = None
        self._mouse_drag_pos = None  # type: Optional[Tuple[int, int]]
Esempio n. 5
0
    def init_gui(self):
        #lets make a menu entry in the sidebar
        self.menu = ui.Scrolling_Menu('view add edit annotations')
        self.g_pool.gui.append(self.menu)
        #add a button to close the plugin
        self.menu.append(ui.Button('close', self.close))

        self.menu.append(
            ui.Info_Text(
                "Annotations recorded with capture are displayed when this plugin is loaded. New annotations can be added with the interface below."
            ))
        self.menu.append(
            ui.Info_Text(
                "If you want to revert annotations to the recorded state, stop player, delete the annotations file in the recording and reopen player."
            ))

        self.menu.append(ui.Text_Input('new_annotation_name', self))
        self.menu.append(ui.Text_Input('new_annotation_hotkey', self))
        self.menu.append(ui.Button('add annotation type', self.add_annotation))
        self.sub_menu = ui.Growing_Menu('Events - click to remove')
        self.menu.append(self.sub_menu)
        self.update_buttons()

        self.on_window_resize(glfwGetCurrentContext(),
                              *glfwGetWindowSize(glfwGetCurrentContext()))

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(24)
        #self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center', h_align='middle')
Esempio n. 6
0
    def __init__(self,
                 g_pool,
                 fullscreen=True,
                 marker_scale=1.0,
                 sample_duration=40):
        super(Screen_Marker_Calibration, self).__init__(g_pool)
        self.detected = False
        self.screen_marker_state = 0.
        self.sample_duration = sample_duration  # number of frames to sample per site
        self.lead_in = 25  #frames of marker shown before starting to sample
        self.lead_out = 5  #frames of markers shown after sampling is donw

        self.active_site = None
        self.sites = []
        self.display_pos = None
        self.on_position = False

        self.markers = []
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None
        self.button = None

        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align='center')
Esempio n. 7
0
    def __init__(self, g_pool, fullscreen=False):
        super(Camera_Intrinsics_Estimation, self).__init__(g_pool)
        self.collect_new = False
        self.calculated = False
        self.obj_grid = _gen_pattern_grid((4, 11))
        self.img_points = []
        self.obj_points = []
        self.count = 10
        self.img_shape = None

        self.display_grid = _make_grid()

        self._window = None

        self.menu = None
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.fullscreen = fullscreen
        self.monitor_idx = 0

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align='center')
    def init_ui(self):
        self.add_menu()
        self.menu.label = "Offline Surface Tracker"
        self.add_button = ui.Thumb(
            "add_surface",
            setter=lambda x: self.add_surface(),
            getter=lambda: False,
            label="A",
            hotkey="a",
        )
        self.g_pool.quickbar.append(self.add_button)

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_color_float((1.0, 1.0, 1.0, 0.8))
        self.glfont.set_align_string(v_align="right", h_align="top")

        self.timeline = ui.Timeline(
            "Surface Tracker",
            self.gl_display_cache_bars,
            self.draw_labels,
            self.timeline_line_height * (len(self.surfaces) + 1),
        )
        self.g_pool.user_timelines.append(self.timeline)

        self.update_gui_markers()
Esempio n. 9
0
    def __init__(self, g_pool, fullscreen=True, marker_scale=1.0,
                 sample_duration=500, monitor_idx=0):
        super().__init__(g_pool)
        self.screen_marker_state = 0.
        self.sample_duration = sample_duration  # number of frames to sample per site
        self.lead_in = 100  # frames of marker shown before starting to sample
        self.lead_out = 15  # frames of markers shown after sampling is donw

        self.active_site = None
        self.sites = []
        self.display_pos = -1., -1.
        self.on_position = False
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None

        self.monitor_idx = monitor_idx
        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')
        self.window_position_default = (0, 0)

        self.circle_tracker = CircleTracker()
        self.markers = []
Esempio n. 10
0
	def open_window(self):
		if not self._window:
			self.input = {'button':None, 'mouse':(0,0)}

			# get glfw started
			if self.run_independently:
				glfwInit()
			window = glfwGetCurrentContext()
			self._window = glfwCreateWindow(self.window_size[0], self.window_size[1], self.name, None, window)
			glfwMakeContextCurrent(self._window)

			if not self._window:
				exit()

			glfwSetWindowPos(self._window,0,0)
			# Register callbacks window
			glfwSetFramebufferSizeCallback(self._window,self.on_resize)
			glfwSetWindowIconifyCallback(self._window,self.on_iconify)
			glfwSetKeyCallback(self._window,self.on_key)
			glfwSetCharCallback(self._window,self.on_char)
			glfwSetMouseButtonCallback(self._window,self.on_button)
			glfwSetCursorPosCallback(self._window,self.on_pos)
			glfwSetScrollCallback(self._window,self.on_scroll)

			# get glfw started
			if self.run_independently:
				init()
			self.basic_gl_setup()

			self.glfont = fs.Context()
			self.glfont.add_font('opensans',get_opensans_font_path())
			self.glfont.set_size(22)
			self.glfont.set_color_float((0.2,0.5,0.9,1.0))
			self.on_resize(self._window,*glfwGetFramebufferSize(self._window))
			glfwMakeContextCurrent(window)
Esempio n. 11
0
    def init_ui(self):
        self.add_menu()
        self.menu.label = "Fixation Detector"

        for help_block in self.__doc__.split("\n\n"):
            help_str = help_block.replace("\n", " ").replace("  ", "").strip()
            self.menu.append(ui.Info_Text(help_str))

        self.menu.append(
            ui.Slider(
                "max_dispersion",
                self,
                min=0.01,
                step=0.1,
                max=5.0,
                label="Maximum Dispersion [degrees]",
            ))
        self.menu.append(
            ui.Slider(
                "min_duration",
                self,
                min=10,
                step=10,
                max=4000,
                label="Minimum Duration [milliseconds]",
            ))

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_size(22)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
Esempio n. 12
0
    def __init__(self,name="unnamed",saved_definition=None):
        self.name = name
        self.markers = {}
        self.detected_markers = 0
        self.defined = False
        self.build_up_status = 0
        self.required_build_up = 90.
        self.detected = False
        self.m_to_screen = None
        self.m_from_screen = None
        self.camera_pose_3d = None
        self.crop_region = None

        self.uid = str(time())
        self.real_world_size = {'x':1.,'y':1.}

        ###window and gui vars
        self._window = None
        self.fullscreen = False
        self.window_should_open = False
        self.window_should_close = False

        self.gaze_on_srf = [] # points on surface for realtime feedback display

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(22)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))


        if saved_definition is not None:
            self.load_from_dict(saved_definition)
Esempio n. 13
0
    def init_ui(self):
        self.add_menu()

        pupil_producer_plugins = [p for p in self.g_pool.plugin_by_name.values() if issubclass(p, Pupil_Producer_Base)]
        pupil_producer_plugins.sort(key=lambda p: p.__name__)

        self.menu_icon.order = 0.29

        def open_plugin(p):
            self.notify_all({'subject': 'start_plugin', 'name': p.__name__})

        # We add the capture selection menu
        self.menu.append(ui.Selector(
                                'pupil_producer',
                                setter=open_plugin,
                                getter=lambda: self.__class__,
                                selection=pupil_producer_plugins,
                                labels=[p.__name__.replace('_', ' ') for p in pupil_producer_plugins],
                                label='Pupil Producers'
                            ))

        self.glfont = fs.Context()
        self.glfont.add_font('opensans', ui.get_opensans_font_path())
        self.glfont.set_font('opensans')
        self.dia_timeline = ui.Timeline('Pupil Diameter [px]', self.draw_pupil_diameter, self.draw_dia_legend)
        self.conf_timeline = ui.Timeline('Pupil Confidence', self.draw_pupil_conf, self.draw_conf_legend)
        self.g_pool.user_timelines.append(self.dia_timeline)
        self.g_pool.user_timelines.append(self.conf_timeline)
Esempio n. 14
0
 def init_ui(self):
     self.glfont = fs.Context()
     self.glfont.add_font('opensans', ui.get_opensans_font_path())
     self.glfont.set_font('opensans')
     self.fps_timeline = ui.Timeline('Recorded FPS', self.draw_fps, self.draw_fps_legend)
     self.fps_timeline.content_height *= 2
     self.g_pool.user_timelines.append(self.fps_timeline)
Esempio n. 15
0
    def __init__(self, g_pool,fullscreen=True,marker_scale=1.0,sample_duration=40):
        super().__init__(g_pool)
        self.detected = False
        self.screen_marker_state = 0.
        self.lead_in = 25  # frames of marker shown before starting to sample


        self.display_pos = (.5,.5)
        self.on_position = False

        self.markers = []
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None

        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')

        # UI Platform tweaks
        if system() == 'Linux':
            self.window_position_default = (0, 0)
        elif system() == 'Windows':
            self.window_position_default = (8, 31)
        else:
            self.window_position_default = (0, 0)
Esempio n. 16
0
    def __init__(self, name="unnamed", saved_definition=None):
        self.name = name
        self.markers = {}
        self.detected_markers = 0
        self.defined = False
        self.build_up_status = 0
        self.required_build_up = 90.
        self.detected = False
        self.m_to_screen = None
        self.m_from_screen = None
        self.camera_pose_3d = None

        self.uid = str(time())
        self.real_world_size = {'x': 1., 'y': 1.}

        ###window and gui vars
        self._window = None
        self.fullscreen = False
        self.window_should_open = False
        self.window_should_close = False

        self.gaze_on_srf = [
        ]  # points on surface for realtime feedback display

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(22)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))

        if saved_definition is not None:
            self.load_from_dict(saved_definition)
Esempio n. 17
0
def draw_markers(img_size,markers, roi=None):

    glfont = fontstash.Context()
    glfont.add_font('opensans',get_opensans_font_path())
    if roi != None:
        glfont.set_size((22 * roi[2]) / float(img_size[1]))
    else:
        glfont.set_size(22)
    glfont.set_color_float((0.2,0.5,0.9,1.0))

    for m in markers:
        #old method using opencv to draw doesn't show the result on screen
        """
        centroid = [m['verts'].sum(axis=0)/4.]
        origin = m['verts'][0]
        hat = np.array([[[0,0],[0,1],[.5,1.25],[1,1],[1,0]]],dtype=np.float32)
        hat = cv2.perspectiveTransform(hat,m_marker_to_screen(m))
        cv2.polylines(img,np.int0(hat),color = (0,0,255),isClosed=True)
        cv2.polylines(img,np.int0(centroid),color = (255,255,0),isClosed=True,thickness=2)
        cv2.putText(img,'id: '+str(m['id']),tuple(np.int0(origin)[0,:]),fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=(255,100,50))


        """
        hat = np.array([[[0,0],[0,1],[.5,1.3],[1,1],[1,0],[0,0]]],dtype=np.float32)
        hat = cv2.perspectiveTransform(hat,m_marker_to_screen(m))
        draw_polyline(hat.reshape((6,2)),1,RGBA(1.0,0,0,1.0))
        glfont.draw_text(m['verts'][0][0][0],m['verts'][0][0][1],'id: '+str(m['id']))
Esempio n. 18
0
    def __init__(self, g_pool,fullscreen=True,marker_scale=1.0,sample_duration=40):
        super(Screen_Marker_Calibration, self).__init__(g_pool)
        self.active = False
        self.detected = False
        self.screen_marker_state = 0.
        self.sample_duration =  sample_duration # number of frames to sample per site
        self.lead_in = 25 #frames of marker shown before starting to sample
        self.lead_out = 5 #frames of markers shown after sampling is donw


        self.active_site = None
        self.sites = []
        self.display_pos = None
        self.on_position = False

        self.markers = []
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None
        self.button = None

        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')
Esempio n. 19
0
 def init_ui(self):
     super().init_ui()
     self.glfont = fs.Context()
     self.glfont.add_font('opensans', ui.get_opensans_font_path())
     self.glfont.set_font('opensans')
     self.timeline = ui.Timeline('Blink Detection', self.draw_activation, self.draw_legend)
     self.timeline.content_height *= 2
     self.g_pool.user_timelines.append(self.timeline)
Esempio n. 20
0
    def init_ui(self):
        self.add_menu()

        pupil_producer_plugins = [
            p for p in self.g_pool.plugin_by_name.values()
            if issubclass(p, Pupil_Producer_Base)
        ]
        pupil_producer_plugins.sort(
            key=lambda p: p.pupil_data_source_selection_label())
        pupil_producer_plugins.sort(
            key=lambda p: p.pupil_data_source_selection_order())
        pupil_producer_labels = [
            p.pupil_data_source_selection_label()
            for p in pupil_producer_plugins
        ]

        self.menu.label = self.plugin_menu_label()
        self.menu_icon.order = 0.29
        self.menu_icon.tooltip = "Pupil Data"

        def open_plugin(p):
            self.notify_all({"subject": "start_plugin", "name": p.__name__})

        # We add the capture selection menu
        self.menu.append(
            ui.Selector(
                "pupil_producer",
                setter=open_plugin,
                getter=lambda: self.__class__,
                selection=pupil_producer_plugins,
                labels=pupil_producer_labels,
                label="Data Source",
            ))

        self.cache = {}
        self.cache_pupil_timeline_data(DATA_KEY_DIAMETER, detector_tag="3d")
        self.cache_pupil_timeline_data(
            DATA_KEY_CONFIDENCE,
            detector_tag="2d",
            ylim=(0.0, 1.0),
            fallback_detector_tag="3d",
        )

        self.glfont = fs.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_font("opensans")

        self.dia_timeline = ui.Timeline(
            label="Pupil Diameter 3D",
            draw_data_callback=self.draw_pupil_diameter,
            draw_label_callback=self.draw_dia_legend,
            content_height=40.0,
        )
        self.conf_timeline = ui.Timeline("Pupil Confidence",
                                         self.draw_pupil_conf,
                                         self.draw_conf_legend)
        self.g_pool.user_timelines.append(self.dia_timeline)
        self.g_pool.user_timelines.append(self.conf_timeline)
Esempio n. 21
0
 def init_ui(self):
     self.glfont = fs.Context()
     self.glfont.add_font("opensans", ui.get_opensans_font_path())
     self.glfont.set_font("opensans")
     self.fps_timeline = ui.Timeline(
         "Recorded FPS", self.draw_fps, self.draw_fps_legend
     )
     self.fps_timeline.content_height *= 2
     self.g_pool.user_timelines.append(self.fps_timeline)
    def init_ui(self):
        super().init_ui()
        self.menu.label = "Offline Calibration"

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', ui.get_opensans_font_path())
        self.glfont.set_color_float((1., 1., 1., 1.))
        self.glfont.set_align_string(v_align='right', h_align='top')

        def use_as_natural_features():
            self.manual_ref_positions.extend(self.circle_marker_positions)
            self.manual_ref_positions.sort(key=lambda mr: mr['index'])

        def jump_next_natural_feature():
            self.manual_ref_positions.sort(key=lambda mr: mr['index'])
            current = self.g_pool.capture.get_frame_index()
            for nf in self.manual_ref_positions:
                if nf['index'] > current:
                    self.notify_all({'subject': 'seek_control.should_seek',
                                     'index': nf['index']})
                    return
            logger.error('No further natural feature available')

        def clear_natural_features():
            self.manual_ref_positions = []

        self.menu.append(ui.Info_Text('"Detection" searches for circle markers in the world video.'))
        # self.menu.append(ui.Button('Redetect', self.start_marker_detection))
        slider = ui.Slider('detection_progress', self, label='Detection Progress', setter=lambda _: _)
        slider.display_format = '%3.0f%%'
        self.menu.append(slider)

        toggle_label = 'Cancel circle marker detection' if self.process_pipe else 'Start circle marker detection'
        self.toggle_detection_button = ui.Button(toggle_label, self.toggle_marker_detection)
        self.menu.append(self.toggle_detection_button)

        self.menu.append(ui.Separator())

        self.menu.append(ui.Button('Use calibration markers as natural features', use_as_natural_features))
        self.menu.append(ui.Button('Jump to next natural feature', jump_next_natural_feature))
        self.menu.append(ui.Switch('manual_ref_edit_mode', self, label="Natural feature edit mode"))
        self.menu.append(ui.Button('Clear natural features', clear_natural_features))

        self.menu.append(ui.Info_Text('Calibration only considers pupil data that has an equal or higher confidence than the minimum calibration confidence.'))
        self.menu.append(ui.Slider('min_calibration_confidence', self.g_pool,
                                   step=.01, min=0.0, max=1.0,
                                   label='Minimum calibration confidence'))

        self.menu.append(ui.Button('Add section', self.append_section))

        # set to minimum height
        self.timeline = ui.Timeline('Calibration Sections', self.draw_sections, self.draw_labels, 1)
        self.g_pool.user_timelines.append(self.timeline)

        for sec in self.sections:
            self.append_section_menu(sec)
        self.on_window_resize(glfw.glfwGetCurrentContext(), *glfw.glfwGetWindowSize(glfw.glfwGetCurrentContext()))
Esempio n. 23
0
 def init_ui(self):
     super().init_ui()
     self.glfont = fs.Context()
     self.glfont.add_font("opensans", ui.get_opensans_font_path())
     self.glfont.set_font("opensans")
     self.timeline = ui.Timeline(
         "Blink Detection", self.draw_activation, self.draw_legend
     )
     self.timeline.content_height *= 2
     self.g_pool.user_timelines.append(self.timeline)
Esempio n. 24
0
    def __init__(self, g_pool, fullscreen=False):
        super(Camera_Intrinsics_Estimation, self).__init__(g_pool)
        self.collect_new = False
        self.calculated = False
        self.obj_grid = _gen_pattern_grid((4, 11))
        self.img_points = []
        self.obj_points = []
        self.count = 10
        self.display_grid = _make_grid()

        self._window = None

        self.menu = None
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.fullscreen = fullscreen
        self.monitor_idx = 0

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align='center')

        self.undist_img = None
        self.show_undistortion = False
        self.show_undistortion_switch = None

        try:
            camera_calibration = load_object(
                os.path.join(self.g_pool.user_dir, 'camera_calibration'))
        except:
            self.camera_intrinsics = None
        else:
            logger.info(
                'Loaded camera calibration. Click show undistortion to verify.'
            )
            logger.info(
                'Hint: Lines in the real world should be straigt in the image.'
            )
            same_name = camera_calibration[
                'camera_name'] == self.g_pool.capture.name
            same_resolution = camera_calibration[
                'resolution'] == self.g_pool.capture.frame_size
            if not (same_name and same_resolution):
                logger.warning(
                    'Loaded camera calibration but camera name and/or resolution has changed. Please re-calibrate.'
                )

            K = camera_calibration['camera_matrix']
            dist_coefs = camera_calibration['dist_coefs']
            resolution = camera_calibration['resolution']
            self.camera_intrinsics = K, dist_coefs, resolution
Esempio n. 25
0
    def init_ui(self):

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center',h_align='middle')

        self.window_size = glfwGetFramebufferSize(glfwGetCurrentContext())
        self.tex = Render_Target(*self.window_size)
        self._socket = zmq_tools.Msg_Receiver(self.g_pool.zmq_ctx,self.g_pool.ipc_sub_url,('logging',))
Esempio n. 26
0
    def init_gui(self):
        from pyglui import ui
        text = ui.Info_Text(self.info_text)
        self.g_pool.capture_source_menu.append(text)

        from pyglui.pyfontstash import fontstash
        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',ui.get_opensans_font_path())
        self.glfont.set_size(64)
        self.glfont.set_color_float((1.,1.,1.,1.0))
        self.glfont.set_align_string(v_align='center',h_align='middle')
Esempio n. 27
0
    def init_gui(self):
        from pyglui import ui
        text = ui.Info_Text(self.info_text)
        self.g_pool.capture_source_menu.append(text)

        from pyglui.pyfontstash import fontstash
        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',ui.get_opensans_font_path())
        self.glfont.set_size(64)
        self.glfont.set_color_float((1.,1.,1.,1.0))
        self.glfont.set_align_string(v_align='center',h_align='middle')
Esempio n. 28
0
    def init_ui(self):
        self.glfont = fs.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_font("opensans")

        for i in range(self.channels):
            eeg_channel = EEG_Channel(i)
            timeline = eeg_channel.set_timeline(self.x, self.y, self.xlim, self.ylim, self.glfont)
            timeline.content_height *= 1
            self.timelines.append(timeline)
            self.g_pool.user_timelines.append(timeline)
Esempio n. 29
0
    def init_ui(self):
        super().init_ui()
        self.menu.label = "Offline Calibration"

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', ui.get_opensans_font_path())
        self.glfont.set_color_float((1., 1., 1., .8))
        self.glfont.set_align_string(v_align='right', h_align='top')

        def jump_next_natural_feature():
            self.manual_ref_positions.sort(key=lambda mr: mr['index'])
            current = self.g_pool.capture.get_frame_index()
            for nf in self.manual_ref_positions:
                if nf['index'] > current:
                    self.g_pool.capture.seek_to_frame(nf['index'])
                    self.g_pool.new_seek = True
                    return
            logger.error('No further natural feature available')

        def clear_natural_features():
            self.manual_ref_positions = []

        self.menu.append(
            ui.Info_Text(
                '"Detection" searches for calibration markers in the world video.'
            ))
        # self.menu.append(ui.Button('Redetect', self.start_detection_task))
        slider = ui.Slider('detection_progress',
                           self,
                           label='Detection Progress',
                           setter=lambda _: _)
        slider.display_format = '%3.0f%%'
        self.menu.append(slider)
        self.menu.append(
            ui.Button('Jump to next natural feature',
                      jump_next_natural_feature))
        self.menu.append(
            ui.Switch('manual_ref_edit_mode',
                      self,
                      label="Natural feature edit mode"))
        self.menu.append(
            ui.Button('Clear natural features', clear_natural_features))
        self.menu.append(ui.Button('Add section', self.append_section))

        # set to minimum height
        self.timeline = ui.Timeline('Calibration Sections', self.draw_sections,
                                    self.draw_labels, 1)
        self.g_pool.user_timelines.append(self.timeline)

        for sec in self.sections:
            self.append_section_menu(sec)
        self.on_window_resize(glfwGetCurrentContext(),
                              *glfwGetWindowSize(glfwGetCurrentContext()))
Esempio n. 30
0
    def __init__(self,g_pool,fullscreen = False):
        super(Chessboard_Calibration, self).__init__(g_pool)

        self.menu = None
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.fullscreen = fullscreen
        self.monitor_idx = 0
        self.nb_img = 10
        self.nb_cols = 10
        self.nb_rows = 7
        self.last_nb_img = self.nb_img
        self.last_nb_cols = self.nb_cols
        self.last_nb_rows = self.nb_rows


        self.collect_new = False
        self.calculated = False
        self.count = self.nb_img
        self.obj_grid = _gen_pattern_grid((self.nb_rows-1,self.nb_cols-1))
        self.img_points = []
        self.obj_points = []
        #self.display_grid = _make_grid()

        self._window = None

        # termination criteria
        self.criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')



        self.undist_img = None
        self.calibrate_img = None
        self.nb_frame = 10
        self.show_undistortion = False
        self.show_undistortion_switch = None


        self.camera_calibration = load_camera_calibration(self.g_pool)
        if self.camera_calibration:
            logger.info('Loaded camera calibration. Click show undistortion to verify.')
            self.camera_intrinsics = self.camera_calibration['camera_matrix'],self.camera_calibration['dist_coefs'],self.camera_calibration['resolution'],self.camera_calibration['error']
        else:
            self.camera_intrinsics = None
Esempio n. 31
0
    def open_window(self):
        if not self.window:
            self.input = {"button": None, "mouse": (0, 0)}

            # get glfw started
            if self.run_independently:
                glfw.init()
                glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
                self.window = glfw.create_window(self.window_size[0],
                                                 self.window_size[1],
                                                 self.name, None, None)
            else:
                self.window = glfw.create_window(
                    self.window_size[0],
                    self.window_size[1],
                    self.name,
                    None,
                    glfw.get_current_context(),
                )

            self.other_window = glfw.get_current_context()

            glfw.make_context_current(self.window)
            glfw.swap_interval(0)
            glfw.set_window_pos(self.window, window_position_default[0],
                                window_position_default[1])
            # Register callbacks window
            glfw.set_framebuffer_size_callback(self.window, self.on_resize)
            glfw.set_window_iconify_callback(self.window, self.on_iconify)
            glfw.set_key_callback(self.window, self.on_window_key)
            glfw.set_char_callback(self.window, self.on_window_char)
            glfw.set_mouse_button_callback(self.window,
                                           self.on_window_mouse_button)
            glfw.set_cursor_pos_callback(self.window, self.on_pos)
            glfw.set_scroll_callback(self.window, self.on_scroll)

            # get glfw started
            if self.run_independently:
                glutils.init()
            self.basic_gl_setup()

            self.sphere = glutils.Sphere(20)

            self.glfont = fs.Context()
            self.glfont.add_font("opensans", get_opensans_font_path())
            self.glfont.set_size(18)
            self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
            self.on_resize(self.window,
                           *glfw.get_framebuffer_size(self.window))
            glfw.make_context_current(self.other_window)
Esempio n. 32
0
    def init_ui(self):

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align="center", h_align="middle")

        self.window_size = glfw.get_framebuffer_size(glfw.get_current_context())
        self.tex = Render_Target(*self.window_size)

        self._socket = zmq_tools.Msg_Receiver(
            self.g_pool.zmq_ctx, self.g_pool.ipc_sub_url, self.subscriptions
        )
Esempio n. 33
0
    def __init__(self, g_pool, name="unnamed", saved_definition=None):
        self.g_pool = g_pool
        self.name = name
        self.markers = {}
        self.detected_markers = 0
        self.defined = False
        self.build_up_status = 0
        self.required_build_up = 90.
        self.detected = False
        self.m_to_screen = None
        self.m_from_screen = None
        self.camera_pose_3d = None
        self.use_distortion = True

        self.uid = str(time())
        self.real_world_size = {'x': 1., 'y': 1.}

        self.heatmap = np.ones(0)
        self.heatmap_detail = .2
        self.heatmap_texture = Named_Texture()
        self.gaze_history = deque()
        self.gaze_history_length = 1.0  # unit: seconds

        # window and gui vars
        self._window = None
        self.fullscreen = False
        self.window_should_open = False
        self.window_should_close = False

        self.gaze_on_srf = [
        ]  # points on surface for realtime feedback display
        self.fixations_on_srf = []  # fixations on surface

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(22)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))

        self.old_corners_robust = None
        if saved_definition is not None:
            self.load_from_dict(saved_definition)

        # UI Platform tweaks
        if system() == 'Linux':
            self.window_position_default = (0, 0)
        elif system() == 'Windows':
            self.window_position_default = (8, 90)
        else:
            self.window_position_default = (0, 0)
    def open_window(self):
        if not self.window:
            self.input = {"button": None, "mouse": (0, 0)}

            # get glfw started
            if self.run_independently:
                glfwInit()
                glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE)
                self.window = glfwCreateWindow(self.window_size[0],
                                               self.window_size[1], self.name,
                                               None)
            else:
                self.window = glfwCreateWindow(
                    self.window_size[0],
                    self.window_size[1],
                    self.name,
                    None,
                    share=glfwGetCurrentContext(),
                )

            self.other_window = glfwGetCurrentContext()

            glfwMakeContextCurrent(self.window)
            glfwSwapInterval(0)
            glfwSetWindowPos(self.window, window_position_default[0],
                             window_position_default[1])
            # Register callbacks window
            glfwSetFramebufferSizeCallback(self.window, self.on_resize)
            glfwSetWindowIconifyCallback(self.window, self.on_iconify)
            glfwSetKeyCallback(self.window, self.on_window_key)
            glfwSetCharCallback(self.window, self.on_window_char)
            glfwSetMouseButtonCallback(self.window,
                                       self.on_window_mouse_button)
            glfwSetCursorPosCallback(self.window, self.on_pos)
            glfwSetScrollCallback(self.window, self.on_scroll)

            # get glfw started
            if self.run_independently:
                glutils.init()
            self.basic_gl_setup()

            self.sphere = glutils.Sphere(20)

            self.glfont = fs.Context()
            self.glfont.add_font("opensans", get_opensans_font_path())
            self.glfont.set_size(18)
            self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
            self.on_resize(self.window, *glfwGetFramebufferSize(self.window))
            glfwMakeContextCurrent(self.other_window)
    def __init__(self,g_pool,fullscreen = False):
        super(Camera_Intrinsics_Estimation, self).__init__(g_pool)
        self.collect_new = False
        self.calculated = False
        self.obj_grid = _gen_pattern_grid((4, 11))
        self.img_points = []
        self.obj_points = []
        self.count = 10
        self.display_grid = _make_grid()

        self._window = None

        self.menu = None
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.fullscreen = fullscreen
        self.monitor_idx = 0


        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')



        self.undist_img = None
        self.show_undistortion = False
        self.show_undistortion_switch = None


        try:
            camera_calibration = load_object(os.path.join(self.g_pool.user_dir,'camera_calibration'))
        except:
            self.camera_intrinsics = None
        else:
            logger.info('Loaded camera calibration. Click show undistortion to verify.')
            logger.info('Hint: Lines in the real world should be straigt in the image.')
            same_name = camera_calibration['camera_name'] == self.g_pool.capture.name
            same_resolution =  camera_calibration['resolution'] == self.g_pool.capture.frame_size
            if not (same_name and same_resolution):
                logger.warning('Loaded camera calibration but camera name and/or resolution has changed. Please re-calibrate.')

            K = camera_calibration['camera_matrix']
            dist_coefs = camera_calibration['dist_coefs']
            resolution = camera_calibration['resolution']
            self.camera_intrinsics = K,dist_coefs,resolution
Esempio n. 36
0
    def init_gui(self):

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center',h_align='middle')

        self.window_size = glfwGetFramebufferSize(glfwGetCurrentContext())
        self.tex = Render_Target(*self.window_size)

        self.log_handler = Log_to_Callback(self.on_log)
        logger = logging.getLogger()
        logger.addHandler(self.log_handler)
        self.log_handler.setLevel(logging.INFO)
Esempio n. 37
0
    def init_gui(self):

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align='center', h_align='middle')

        self.window_size = glfwGetFramebufferSize(glfwGetCurrentContext())
        self.tex = Render_Target(*self.window_size)

        self.log_handler = Log_to_Callback(self.on_log)
        logger = logging.getLogger()
        logger.addHandler(self.log_handler)
        self.log_handler.setLevel(logging.INFO)
Esempio n. 38
0
    def open_window(self):
        if not self.window:
            self.input = {"button": None, "mouse": (0, 0)}

            # get glfw started
            if self.run_independently:
                glfwInit()
                self.window = glfwCreateWindow(
                    self.window_size[0], self.window_size[1], self.name, None
                )
            else:
                self.window = glfwCreateWindow(
                    self.window_size[0],
                    self.window_size[1],
                    self.name,
                    None,
                    share=glfwGetCurrentContext(),
                )

            self.other_window = glfwGetCurrentContext()

            glfwMakeContextCurrent(self.window)
            glfwSwapInterval(0)
            glfwSetWindowPos(
                self.window, window_position_default[0], window_position_default[1]
            )
            # Register callbacks window
            glfwSetFramebufferSizeCallback(self.window, self.on_resize)
            glfwSetWindowIconifyCallback(self.window, self.on_iconify)
            glfwSetKeyCallback(self.window, self.on_window_key)
            glfwSetCharCallback(self.window, self.on_window_char)
            glfwSetMouseButtonCallback(self.window, self.on_window_mouse_button)
            glfwSetCursorPosCallback(self.window, self.on_pos)
            glfwSetScrollCallback(self.window, self.on_scroll)

            # get glfw started
            if self.run_independently:
                glutils.init()
            self.basic_gl_setup()

            self.sphere = glutils.Sphere(20)

            self.glfont = fs.Context()
            self.glfont.add_font("opensans", get_opensans_font_path())
            self.glfont.set_size(18)
            self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
            self.on_resize(self.window, *glfwGetFramebufferSize(self.window))
            glfwMakeContextCurrent(self.other_window)
    def init_ui(self):
        self.add_menu()
        self.menu.label = type(self).MENU_LABEL_TEXT

        for help_block in self.__doc__.split("\n\n"):
            help_str = help_block.replace("\n", " ").replace("  ", "").strip()
            self.menu.append(gl_ui.Info_Text(help_str))

        color_legend_text = ui.color_from_segment.__doc__
        color_legend_text = color_legend_text.strip()
        color_legend_text = color_legend_text.replace("  ", "")
        color_legend_text = color_legend_text.replace("\n-", "\n    -")
        self.menu.append(gl_ui.Info_Text(color_legend_text))

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", gl_ui.get_opensans_font_path())
 def __init__(self, marker_scale: float):
     # Public properties
     self.marker_scale = marker_scale
     self.is_marker_detected = False
     # Private state
     self.__state: _MarkerWindowState = MarkerWindowStateClosed()
     self.__window = GUIWindow()
     self.__window.add_observer("on_left_click", self._on_left_click)
     self.__window.add_observer("on_key_press_escape",
                                self._on_key_press_escape)
     # Private font
     self.__glfont = fontstash.Context()
     self.__glfont.add_font("opensans", get_opensans_font_path())
     self.__glfont.set_size(32)
     self.__glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
     self.__glfont.set_align_string(v_align="center")
    def init_ui(self):
        self.add_menu()
        self.menu.label = type(self).MENU_LABEL_TEXT

        for help_block in self.__doc__.split("\n\n"):
            help_str = help_block.replace("\n", " ").replace("  ", "").strip()
            self.menu.append(gl_ui.Info_Text(help_str))

        color_legend_text = ui.color_from_segment.__doc__
        color_legend_text = color_legend_text.strip()
        color_legend_text = color_legend_text.replace("  ", "")
        color_legend_text = color_legend_text.replace("\n-", "\n    -")
        self.menu.append(gl_ui.Info_Text(color_legend_text))

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", gl_ui.get_opensans_font_path())
Esempio n. 42
0
    def init_ui(self):
        self.add_menu()
        self.menu.label = 'Offline Surface Tracker'
        self.add_button = ui.Thumb('add_surface',setter=lambda x: self.add_surface(),getter=lambda:False,label='A',hotkey='a')
        self.g_pool.quickbar.append(self.add_button)

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans', ui.get_opensans_font_path())
        self.glfont.set_color_float((1., 1., 1., .8))
        self.glfont.set_align_string(v_align='right', h_align='top')

        self.timeline = ui.Timeline('Surface Tracker', self.gl_display_cache_bars, self.draw_labels,
                                    self.timeline_line_height * (len(self.surfaces) + 1))
        self.g_pool.user_timelines.append(self.timeline)

        self.update_gui_markers()
Esempio n. 43
0
    def __init__(self, g_pool,fullscreen=True,marker_scale=1.0,sample_duration=45):
        super().__init__(g_pool)
        self.detected = False
        self.screen_marker_state = 0.
        self.sample_duration =  sample_duration # number of frames to sample per site
        self.fixation_boost = sample_duration/2.
        self.lead_in = 25 #frames of marker shown before starting to sample
        self.lead_out = 5 #frames of markers shown after sampling is donw
        self.black_duration = 15
        self.session_settings = Persistent_Dict(os.path.join(g_pool.user_dir,'user_settings_screen_calibration') )

        self.active_site = None
        self.sites = []
        self.display_pos = None
        self.on_position = False


        self.screen_markers = [[],[],[],[],[],[], []]
        self.encode_markers()


        self.markers = []
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None
        self.button = None

        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')

        # UI Platform tweaks
        if system() == 'Linux':
            self.window_position_default = (0, 0)
        elif system() == 'Windows':
            self.window_position_default = (8, 31)
        else:
            self.window_position_default = (0, 0)
    def __init__(
        self,
        g_pool,
        marker_mode="Full screen",
        marker_scale=1.0,
        sample_duration=40,
        monitor_idx=0,
    ):
        super().__init__(g_pool)
        self.screen_marker_state = 0.0
        self.lead_in = 25  # frames of marker shown before starting to sample

        self.display_pos = (0.5, 0.5)
        self.on_position = False
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None

        self.stop_marker_found = False
        self.auto_stop = 0
        self.auto_stop_max = 30

        self.monitor_idx = monitor_idx
        self.marker_mode = marker_mode
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align="center")

        # UI Platform tweaks
        if system() == "Linux":
            self.window_position_default = (0, 0)
        elif system() == "Windows":
            self.window_position_default = (8, 90)
        else:
            self.window_position_default = (0, 0)

        self.circle_tracker = CircleTracker()
        self.markers = []
    def __init__(
        self,
        g_pool,
        fullscreen=True,
        marker_scale=1.0,
        sample_duration=40,
        monitor_idx=0,
    ):
        super().__init__(g_pool)
        self.screen_marker_state = 0.0
        self.sample_duration = sample_duration  # number of frames to sample per site
        self.lead_in = 25  # frames of marker shown before starting to sample
        self.lead_out = 5  # frames of markers shown after sampling is donw

        self.active_site = None
        self.sites = []
        self.display_pos = -1.0, -1.0
        self.on_position = False
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None

        self.monitor_idx = monitor_idx
        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align="center")

        # UI Platform tweaks
        if system() == "Linux":
            self.window_position_default = (0, 0)
        elif system() == "Windows":
            self.window_position_default = (8, 90)
        else:
            self.window_position_default = (0, 0)

        self.circle_tracker = CircleTracker()
        self.markers = []
    def __init__(self, g_pool, fullscreen=False, monitor_idx=0):
        super().__init__(g_pool)
        self.collect_new = False
        self.calculated = False
        self.obj_grid = _gen_pattern_grid((4, 11))
        self.img_points = []
        self.obj_points = []
        self.count = 10
        self.display_grid = _make_grid()

        self._window = None

        self.menu = None
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.monitor_idx = monitor_idx
        self.fullscreen = fullscreen
        self.dist_mode = "Fisheye"

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
        self.glfont.set_align_string(v_align="center")

        self.undist_img = None
        self.show_undistortion = False
        self.show_undistortion_switch = None

        if (
            hasattr(self.g_pool.capture, "intrinsics")
            and self.g_pool.capture.intrinsics
        ):
            logger.info(
                "Click show undistortion to verify camera intrinsics calibration."
            )
            logger.info(
                "Hint: Straight lines in the real world should be straigt in the image."
            )
        else:
            logger.info(
                "No camera intrinsics calibration is currently set for this camera!"
            )
Esempio n. 47
0
    def init_ui(self):
        self.add_menu()
        self.menu.label = "Fixation Detector"

        for help_block in self.__doc__.split("\n\n"):
            help_str = help_block.replace("\n", " ").replace("  ", "").strip()
            self.menu.append(ui.Info_Text(help_str))

        self.menu.append(
            ui.Slider(
                "max_dispersion",
                self,
                min=0.01,
                step=0.1,
                max=5.0,
                label="Maximum Dispersion [degrees]",
            )
        )
        self.menu.append(
            ui.Slider(
                "min_duration",
                self,
                min=10,
                step=10,
                max=4000,
                label="Minimum Duration [milliseconds]",
            )
        )

        self.menu.append(
            ui.Slider(
                "confidence_threshold",
                self,
                min=0.0,
                max=1.0,
                label="Confidence Threshold",
            )
        )

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_size(22)
        self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
Esempio n. 48
0
    def init_ui(self):
        self.add_menu()

        pupil_producer_plugins = [
            p
            for p in self.g_pool.plugin_by_name.values()
            if issubclass(p, Pupil_Producer_Base)
        ]
        pupil_producer_plugins.sort(key=lambda p: p.__name__)

        self.menu_icon.order = 0.29

        def open_plugin(p):
            self.notify_all({"subject": "start_plugin", "name": p.__name__})

        # We add the capture selection menu
        self.menu.append(
            ui.Selector(
                "pupil_producer",
                setter=open_plugin,
                getter=lambda: self.__class__,
                selection=pupil_producer_plugins,
                labels=[p.__name__.replace("_", " ") for p in pupil_producer_plugins],
                label="Pupil Producers",
            )
        )

        self.cache = {}
        self.cache_pupil_timeline_data("diameter")
        self.cache_pupil_timeline_data("confidence")

        self.glfont = fs.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_font("opensans")

        self.dia_timeline = ui.Timeline(
            "Pupil Diameter [px]", self.draw_pupil_diameter, self.draw_dia_legend
        )
        self.conf_timeline = ui.Timeline(
            "Pupil Confidence", self.draw_pupil_conf, self.draw_conf_legend
        )
        self.g_pool.user_timelines.append(self.dia_timeline)
        self.g_pool.user_timelines.append(self.conf_timeline)
Esempio n. 49
0
    def init_gui(self):

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center',h_align='middle')

        self.window_size = glfwGetFramebufferSize(glfwGetCurrentContext())
        self.tex = Render_Target(*self.window_size)
        if self.g_pool.app == 'capture':
            self._socket = zmq_tools.Msg_Receiver(self.g_pool.zmq_ctx,self.g_pool.ipc_sub_url,('logging',))
            self._poller = zmq_tools.zmq.Poller()
            self._poller.register(self._socket.socket)
        else:
            self._socket = None
            self.log_handler = Log_to_Callback(self.on_log)
            logger = logging.getLogger()
            logger.addHandler(self.log_handler)
            self.log_handler.setLevel(logging.INFO)
Esempio n. 50
0
    def __init__(self, plugin, title, timeline_ui_parent, all_timestamps):
        self._timeline_ui_parent = timeline_ui_parent
        self._all_timestamps = all_timestamps
        self._time_start = all_timestamps[0]
        self._time_end = all_timestamps[-1]

        self._rows = []

        # initially set to minimum height
        self._timeline = ui.Timeline(
            title, self.draw_sections, self.draw_labels, content_height=1
        )

        self.glfont = fontstash.Context()
        self.glfont.add_font("opensans", ui.get_opensans_font_path())
        self.glfont.set_color_float((1.0, 1.0, 1.0, 1.0))
        self.glfont.set_align_string(v_align="right", h_align="top")

        plugin.add_observer("init_ui", self._on_init_ui)
        plugin.add_observer("deinit_ui", self._on_deinit_ui)
Esempio n. 51
0
    def __init__(self,name="unnamed",saved_definition=None):
        self.name = name
        self.markers = {}
        self.detected_markers = 0
        self.defined = False
        self.build_up_status = 0
        self.required_build_up = 90.
        self.detected = False
        self.m_to_screen = None
        self.m_from_screen = None
        self.camera_pose_3d = None
        self.use_distortion = 0

        self.uid = str(time())
        self.real_world_size = {'x':1.,'y':1.}

        ###window and gui vars
        self._window = None
        self.fullscreen = False
        self.window_should_open = False
        self.window_should_close = False

        self.gaze_on_srf = [] # points on surface for realtime feedback display

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(22)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))


        self.old_corners_robust = None
        if saved_definition is not None:
            self.load_from_dict(saved_definition)

        # UI Platform tweaks
        if system() == 'Linux':
            self.window_position_default = (0, 0)
        elif system() == 'Windows':
            self.window_position_default = (8, 31)
        else:
            self.window_position_default = (0, 0)
Esempio n. 52
0
    def __init__(self, g_pool,menu_conf = {'collapsed':True},fullscreen=True,marker_scale=1.0):
        super(Screen_Marker_Calibration, self).__init__(g_pool)
        self.active = False
        self.detected = False
        self.screen_marker_state = 0.
        self.sample_duration = 40 # number of frames
        self.screen_marker_max = 70 # number of frames, maximum bound for state
        self.start_sample = 15 # (screen_marker_max - sample_duration) / 2
        self.stop_sample = 55

        self.active_site = 0
        self.sites = []
        self.display_pos = None
        self.on_position = False

        self.candidate_ellipses = []
        self.pos = None

        self.show_edges = 0
        self.dist_threshold = 5
        self.area_threshold = 20
        self.marker_scale = marker_scale
        self.pattern_alpha = 1.0

        self.world_size = None

        self._window = None

        self.menu = None
        self.menu_conf = menu_conf
        self.button = None

        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')
Esempio n. 53
0
    def __init__(self,g_pool,fullscreen = False):
        super(Camera_Intrinsics_Estimation, self).__init__(g_pool)
        self.collect_new = False
        self.calculated = False
        self.obj_grid = _gen_pattern_grid((4, 11))
        self.img_points = []
        self.obj_points = []
        self.count = 10
        self.display_grid = _make_grid()

        self._window = None

        self.menu = None
        self.button = None
        self.clicks_to_close = 5
        self.window_should_close = False
        self.fullscreen = fullscreen
        self.monitor_idx = 0


        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')



        self.undist_img = None
        self.show_undistortion = False
        self.show_undistortion_switch = None


        self.camera_calibration = load_camera_calibration(self.g_pool)
        if self.camera_calibration:
            logger.info('Loaded camera calibration. Click show undistortion to verify.')
            logger.info('Hint: Straight lines in the real world should be straigt in the image.')
            self.camera_intrinsics = self.camera_calibration['camera_matrix'],self.camera_calibration['dist_coefs'],self.camera_calibration['resolution']
        else:
            self.camera_intrinsics = None
Esempio n. 54
0
    def init_gui(self):
        #lets make a menu entry in the sidebar
        self.menu = ui.Scrolling_Menu('view add edit annotations')
        self.g_pool.gui.append(self.menu)

        #add a button to close the plugin
        self.menu.append(ui.Button('close',self.close))
        self.menu.append(ui.Text_Input('new_annotation_name',self))
        self.menu.append(ui.Text_Input('new_annotation_hotkey',self))
        self.menu.append(ui.Button('add annotation type',self.add_annotation))
        self.sub_menu = ui.Growing_Menu('Events - click to remove')
        self.menu.append(self.sub_menu)
        self.update_buttons()


        self.on_window_resize(glfwGetCurrentContext(),*glfwGetWindowSize(glfwGetCurrentContext()))

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(24)
        #self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center',h_align='middle')
Esempio n. 55
0
    def __init__(self, g_pool,fullscreen=True,marker_scale=1.0,sample_duration=40):
        super().__init__(g_pool)
        self.detected = False
        self.screen_marker_state = 0.
        self.lead_in = 25  # frames of marker shown before starting to sample


        self.display_pos = (.5,.5)
        self.on_position = False

        self.markers = []
        self.pos = None

        self.marker_scale = marker_scale

        self._window = None

        self.menu = None
        self.button = None

        self.fullscreen = fullscreen
        self.clicks_to_close = 5

        self.glfont = fontstash.Context()
        self.glfont.add_font('opensans',get_opensans_font_path())
        self.glfont.set_size(32)
        self.glfont.set_color_float((0.2,0.5,0.9,1.0))
        self.glfont.set_align_string(v_align='center')

        # UI Platform tweaks
        if system() == 'Linux':
            self.window_position_default = (0, 0)
        elif system() == 'Windows':
            self.window_position_default = (8, 31)
        else:
            self.window_position_default = (0, 0)
Esempio n. 56
0
 def _setup_glfont(self):
     self.glfont = fontstash.Context()
     self.glfont.add_font("opensans", get_opensans_font_path())
     self.glfont.set_size(20)
     self.glfont.set_color_float((0.8, 0.2, 0.1, 0.8))