Пример #1
0
    def gl_display_in_window(self,world_tex_id):
        """
        here we map a selected surface onto a seperate window.
        """
        if self._window and self.detected:
            active_window = glfwGetCurrentContext()
            glfwMakeContextCurrent(self._window)
            clear_gl_screen()

            # cv uses 3x3 gl uses 4x4 tranformation matricies
            m = cvmat_to_glmat(self.m_from_screen)

            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            glOrtho(0, 1, 0, 1,-1,1) # gl coord convention

            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            #apply m  to our quad - this will stretch the quad such that the ref suface will span the window extends
            glLoadMatrixf(m)

            draw_named_texture(world_tex_id)
            glMatrixMode(GL_PROJECTION)
            glPopMatrix()
            glMatrixMode(GL_MODELVIEW)
            glPopMatrix()

            # now lets get recent pupil positions on this surface:
            draw_points_norm(self.gaze_on_srf,color=RGBA(0.,8.,.5,.8), size=80)

            glfwSwapBuffers(self._window)
            glfwMakeContextCurrent(active_window)
        if self.window_should_close:
            self.close_window()
Пример #2
0
    def _draw_heatmap(self, surface):
        # TODO The heatmap is computed in undistorted space. For the visualization to
        # be precisely correct we would have to distort the heatmap accordingly.
        if self.heatmap_mode == Heatmap_Mode.WITHIN_SURFACE:
            self.heatmap_textures[surface].update_from_ndarray(
                surface.within_surface_heatmap
            )
        else:
            self.heatmap_textures[surface].update_from_ndarray(
                surface.across_surface_heatmap
            )
        width, height = self.tracker.camera_model.resolution
        img_corners = np.array(
            [(0, height), (width, height), (width, 0), (0, 0)], dtype=np.float32
        )
        norm_trans = _get_points_to_norm_trans(img_corners)

        trans_mat = norm_trans @ surface.surf_to_dist_img_trans
        trans_mat = gl_utils.cvmat_to_glmat(trans_mat)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.glOrtho(0, 1, 0, 1, -1, 1)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        # apply trans_mat  to our quad - this will stretch the quad such that the ref suface will span the window extends
        gl.glLoadMatrixf(trans_mat)
        self.heatmap_textures[surface].draw()
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPopMatrix()
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPopMatrix()
Пример #3
0
    def _draw_heatmap(self, surface):
        # TODO The heatmap is computed in undistorted space. For the visualization to
        # be precisely correct we would have to distort the heatmap accordingly.
        if self.heatmap_mode == Heatmap_Mode.WITHIN_SURFACE:
            self.heatmap_textures[surface].update_from_ndarray(
                surface.within_surface_heatmap
            )
        else:
            self.heatmap_textures[surface].update_from_ndarray(
                surface.across_surface_heatmap
            )
        width, height = self.tracker.camera_model.resolution
        img_corners = np.array(
            [(0, height), (width, height), (width, 0), (0, 0)], dtype=np.float32
        )
        norm_trans = _get_points_to_norm_trans(img_corners)

        trans_mat = norm_trans @ surface.surf_to_dist_img_trans
        trans_mat = gl_utils.cvmat_to_glmat(trans_mat)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.glOrtho(0, 1, 0, 1, -1, 1)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        # apply trans_mat  to our quad - this will stretch the quad such that the ref suface will span the window extends
        gl.glLoadMatrixf(trans_mat)
        self.heatmap_textures[surface].draw()
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPopMatrix()
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPopMatrix()
Пример #4
0
    def gl_display_in_window(self,world_tex):
        """
        here we map a selected surface onto a seperate window.
        """
        if self._window and self.detected:
            active_window = glfwGetCurrentContext()
            glfwMakeContextCurrent(self._window)
            clear_gl_screen()

            # cv uses 3x3 gl uses 4x4 tranformation matricies
            m = cvmat_to_glmat(self.m_from_screen)

            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            glOrtho(0, 1, 0, 1,-1,1) # gl coord convention

            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            #apply m  to our quad - this will stretch the quad such that the ref suface will span the window extends
            glLoadMatrixf(m)

            world_tex.draw()

            glMatrixMode(GL_PROJECTION)
            glPopMatrix()
            glMatrixMode(GL_MODELVIEW)
            glPopMatrix()

            # now lets get recent pupil positions on this surface:
            for gp in self.gaze_on_srf:
                draw_points_norm([gp['norm_pos']],color=RGBA(0.0,0.8,0.5,0.8), size=80)

            glfwSwapBuffers(self._window)
            glfwMakeContextCurrent(active_window)
Пример #5
0
    def gl_display_in_window_3d(self, world_tex):
        """
        here we map a selected surface onto a seperate window.
        """
        K, img_size = (
            self.g_pool.capture.intrinsics.K,
            self.g_pool.capture.intrinsics.resolution,
        )

        if self._window and self.camera_pose_3d is not None:
            active_window = glfwGetCurrentContext()
            glfwMakeContextCurrent(self._window)
            glClearColor(0.8, 0.8, 0.8, 1.0)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glClearDepth(1.0)
            glDepthFunc(GL_LESS)
            glEnable(GL_DEPTH_TEST)
            self.trackball.push()

            glMatrixMode(GL_MODELVIEW)

            draw_coordinate_system(l=self.real_world_size["x"])
            glPushMatrix()
            glScalef(self.real_world_size["x"], self.real_world_size["y"], 1)
            draw_polyline(
                [[0, 0], [0, 1], [1, 1], [1, 0]],
                color=RGBA(0.5, 0.3, 0.1, 0.5),
                thickness=3,
            )
            glPopMatrix()
            # Draw the world window as projected onto the plane using the homography mapping
            glPushMatrix()
            glScalef(self.real_world_size["x"], self.real_world_size["y"], 1)
            # cv uses 3x3 gl uses 4x4 tranformation matricies
            m = cvmat_to_glmat(self.m_from_screen)
            glMultMatrixf(m)
            glTranslatef(0, 0, -0.01)
            world_tex.draw()
            draw_polyline(
                [[0, 0], [0, 1], [1, 1], [1, 0]],
                color=RGBA(0.5, 0.3, 0.6, 0.5),
                thickness=3,
            )
            glPopMatrix()

            # Draw the camera frustum and origin using the 3d tranformation obtained from solvepnp
            glPushMatrix()
            glMultMatrixf(self.camera_pose_3d.T.flatten())
            draw_frustum(img_size, K, 150)
            glLineWidth(1)
            draw_frustum(img_size, K, 0.1)
            draw_coordinate_system(l=5)
            glPopMatrix()

            self.trackball.pop()

            glfwSwapBuffers(self._window)
            glfwMakeContextCurrent(active_window)
Пример #6
0
    def gl_display_in_window_3d(self,world_tex,camera_intrinsics):
        """
        here we map a selected surface onto a seperate window.
        """
        K,dist_coef,img_size = camera_intrinsics['camera_matrix'],camera_intrinsics['dist_coefs'],camera_intrinsics['resolution']

        if self._window and self.camera_pose_3d is not None:
            active_window = glfwGetCurrentContext()
            glfwMakeContextCurrent(self._window)
            glClearColor(.8,.8,.8,1.)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glClearDepth(1.0)
            glDepthFunc(GL_LESS)
            glEnable(GL_DEPTH_TEST)
            self.trackball.push()

            glMatrixMode(GL_MODELVIEW)

            draw_coordinate_system(l=self.real_world_size['x'])
            glPushMatrix()
            glScalef(self.real_world_size['x'],self.real_world_size['y'],1)
            draw_polyline([[0,0],[0,1],[1,1],[1,0]],color = RGBA(.5,.3,.1,.5),thickness=3)
            glPopMatrix()
            # Draw the world window as projected onto the plane using the homography mapping
            glPushMatrix()
            glScalef(self.real_world_size['x'], self.real_world_size['y'], 1)
            # cv uses 3x3 gl uses 4x4 tranformation matricies
            m = cvmat_to_glmat(self.m_from_screen)
            glMultMatrixf(m)
            glTranslatef(0,0,-.01)
            world_tex.draw()
            draw_polyline([[0,0],[0,1],[1,1],[1,0]],color = RGBA(.5,.3,.6,.5),thickness=3)
            glPopMatrix()

            # Draw the camera frustum and origin using the 3d tranformation obtained from solvepnp
            glPushMatrix()
            glMultMatrixf(self.camera_pose_3d.T.flatten())
            draw_frustum(img_size, K, 150)
            glLineWidth(1)
            draw_frustum(img_size, K, .1)
            draw_coordinate_system(l=5)
            glPopMatrix()


            self.trackball.pop()

            glfwSwapBuffers(self._window)
            glfwMakeContextCurrent(active_window)
        if self.window_should_close:
            self.close_window()
Пример #7
0
    def gl_display_heatmap(self):
        if self.detected:
            m = cvmat_to_glmat(self.m_to_screen)

            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            glOrtho(0, 1, 0, 1, -1, 1)  # gl coord convention

            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            # apply m  to our quad - this will stretch the quad such that the ref suface will span the window extends
            glLoadMatrixf(m)

            self.heatmap_texture.draw()

            glMatrixMode(GL_PROJECTION)
            glPopMatrix()
            glMatrixMode(GL_MODELVIEW)
            glPopMatrix()
Пример #8
0
    def gl_display_metrics(self):
        if self.metrics_texture and self.detected:
            # cv uses 3x3 gl uses 4x4 tranformation matricies
            m = cvmat_to_glmat(self.m_to_screen)

            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            glOrtho(0, 1, 0, 1, -1, 1)  # gl coord convention

            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            # apply m  to our quad - this will stretch the quad such that the ref suface will span the window extends
            glLoadMatrixf(m)

            self.metrics_texture.draw()

            glMatrixMode(GL_PROJECTION)
            glPopMatrix()
            glMatrixMode(GL_MODELVIEW)
            glPopMatrix()
Пример #9
0
    def gl_display_in_window(self,surface):
        """
        here we map a selected surface onto a seperate window.
        """
        active_window = glfwGetCurrentContext()
        glfwMakeContextCurrent(self._window)
        clear_gl_screen()

        # cv uses 3x3 gl uses 4x4 tranformation matricies
        m = cvmat_to_glmat(surface.m_from_screen)

        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        gluOrtho2D(0, 1, 0, 1) # gl coord convention

        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        #apply m  to our quad - this will stretch the quad such that the ref suface will span the window extends
        glLoadMatrixf(m)

        #redraw will use the most recent world img texture and use it again.
        redraw_gl_texture( ((0,0),(1,0),(1,1),(0,1)) )

        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()


        #now lets get recent pupil positions on this surface:
        try:
            gaze_on_surface = [p['realtime gaze on '+surface.name] for p in self.recent_pupil_positions]
        except KeyError:
            gaze_on_surface = []
        draw_gl_points_norm(gaze_on_surface,color=(0.,8.,.5,.8), size=80)


        glfwSwapBuffers(self._window)
        glfwMakeContextCurrent(active_window)
Пример #10
0
    def gl_display_in_window(self, world_tex):
        """
        here we map a selected surface onto a separate window.
        """
        if self._window and self.surface.detected:
            active_window = glfw.get_current_context()
            glfw.make_context_current(self._window)
            gl_utils.clear_gl_screen()

            # cv uses 3x3 gl uses 4x4 transformation matrices
            width, height = self.tracker.camera_model.resolution
            img_corners = np.array(
                [(0, height), (width, height), (width, 0), (0, 0)], dtype=np.float32
            )
            denorm_trans = _get_norm_to_points_trans(img_corners)

            trans_mat = self.surface.dist_img_to_surf_trans @ denorm_trans
            trans_mat = gl_utils.cvmat_to_glmat(trans_mat)

            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glPushMatrix()
            gl.glLoadIdentity()
            gl.glOrtho(0, 1, 0, 1, -1, 1)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            # apply trans_mat to our quad - this will stretch the quad such that the
            # surface will span the window extends
            gl.glLoadMatrixf(trans_mat)

            world_tex.draw()

            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glPopMatrix()
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPopMatrix()

            self.draw_recent_pupil_positions()

            glfw.swap_buffers(self._window)
            glfw.make_context_current(active_window)
Пример #11
0
    def gl_display_in_window(self, world_tex):
        """
        here we map a selected surface onto a separate window.
        """
        if self._window and self.surface.detected:
            active_window = glfw.glfwGetCurrentContext()
            glfw.glfwMakeContextCurrent(self._window)
            gl_utils.clear_gl_screen()

            # cv uses 3x3 gl uses 4x4 transformation matrices
            width, height = self.tracker.camera_model.resolution
            img_corners = np.array(
                [(0, height), (width, height), (width, 0), (0, 0)], dtype=np.float32
            )
            denorm_trans = _get_norm_to_points_trans(img_corners)

            trans_mat = self.surface.dist_img_to_surf_trans @ denorm_trans
            trans_mat = gl_utils.cvmat_to_glmat(trans_mat)

            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glPushMatrix()
            gl.glLoadIdentity()
            gl.glOrtho(0, 1, 0, 1, -1, 1)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            # apply trans_mat to our quad - this will stretch the quad such that the
            # surface will span the window extends
            gl.glLoadMatrixf(trans_mat)

            world_tex.draw()

            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glPopMatrix()
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPopMatrix()

            self.draw_recent_pupil_positions()

            glfw.glfwSwapBuffers(self._window)
            glfw.glfwMakeContextCurrent(active_window)
Пример #12
0
    def gl_display_in_window(self, surface):
        """
        here we map a selected surface onto a seperate window.
        """
        active_window = glfwGetCurrentContext()
        glfwMakeContextCurrent(self._window)
        clear_gl_screen()

        # cv uses 3x3 gl uses 4x4 tranformation matricies
        m = cvmat_to_glmat(surface.m_from_screen)

        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        gluOrtho2D(0, 1, 0, 1)  # gl coord convention

        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        #apply m  to our quad - this will stretch the quad such that the ref suface will span the window extends
        glLoadMatrixf(m)

        draw_named_texture(self.g_pool.image_tex)

        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()

        #now lets get recent pupil positions on this surface:
        try:
            gaze_on_surface = [
                p['realtime gaze on ' + surface.name]
                for p in self.recent_pupil_positions
            ]
        except KeyError:
            gaze_on_surface = []
        draw_gl_points_norm(gaze_on_surface, color=(0., 8., .5, .8), size=80)

        glfwSwapBuffers(self._window)
        glfwMakeContextCurrent(active_window)
Пример #13
0
    def gl_display_heatmap(self):
        if self.heatmap_texture and self.detected:

            # cv uses 3x3 gl uses 4x4 tranformation matricies
            m = cvmat_to_glmat(self.m_to_screen)

            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            glOrtho(0, 1, 0, 1,-1,1) # gl coord convention

            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            #apply m  to our quad - this will stretch the quad such that the ref suface will span the window extends
            glLoadMatrixf(m)

            self.heatmap_texture.draw()

            glMatrixMode(GL_PROJECTION)
            glPopMatrix()
            glMatrixMode(GL_MODELVIEW)
            glPopMatrix()