当前位置: 首页>>代码示例>>Python>>正文


Python GL.glReadPixels方法代码示例

本文整理汇总了Python中OpenGL.GL.glReadPixels方法的典型用法代码示例。如果您正苦于以下问题:Python GL.glReadPixels方法的具体用法?Python GL.glReadPixels怎么用?Python GL.glReadPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenGL.GL的用法示例。


在下文中一共展示了GL.glReadPixels方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_fbo_color_rgba32f

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def read_fbo_color_rgba32f(fbo):
        """
        Read the color attachment from a FBO, assuming it is GL_RGBA_32F.
        # Ref: https://github.com/julienr/vertex_visibility/blob/master/depth.py
        """
        h, w = fbo.color_buffer.shape[:2]
        x, y = 0, 0
        im = gl.glReadPixels(x, y, w, h, gl.GL_RGBA, gl.GL_FLOAT)
        im = np.frombuffer(im, np.float32)
        im.shape = h, w, 4
        im = im[::-1, :]

        return im

#-------------------------------------------------------------------------------
# Ref: https://github.com/vispy/vispy/blob/master/examples/demo/gloo/offscreen.py 
开发者ID:meiqua,项目名称:patch_linemod,代码行数:18,代码来源:renderer.py

示例2: finish

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def finish(self):

        im = gl.glReadPixels(0, 0, self.size[0], self.size[1], gl.GL_RGB, gl.GL_FLOAT)
        rgb = np.copy(np.frombuffer(im, np.float32)).reshape(self.shape+(3,))[::-1, :]  # Read buffer and flip Y
        im = gl.glReadPixels(0, 0, self.size[0], self.size[1], gl.GL_DEPTH_COMPONENT, gl.GL_FLOAT)
        dep = np.copy(np.frombuffer(im, np.float32)).reshape(self.shape+(1,))[::-1, :]  # Read buffer and flip Y

        # Convert z-buffer to depth map
        mult = (self.clip_near*self.clip_far)/(self.clip_near-self.clip_far)
        addi = self.clip_far/(self.clip_near-self.clip_far)
        bg = dep == 1
        dep = mult/(dep + addi)
        dep[bg] = 0
        return rgb, np.squeeze(dep) 
开发者ID:kirumang,项目名称:Pix2Pose,代码行数:16,代码来源:renderer.py

示例3: _blockUnderCursor

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def _blockUnderCursor(self, center=False):
        """
            returns a point in 3d space that was determined by
         reading the depth buffer value
        """
        try:
            GL.glReadBuffer(GL.GL_BACK)
        except Exception:
            logging.exception('Exception during glReadBuffer')
        ws = self.root.size
        if center:
            x, y = ws
            x //= 2
            y //= 2
        else:
            x, y = mouse.get_pos()
        if (x < 0 or y < 0 or x >= ws[0] or
                    y >= ws[1]):
            return 0, 0, 0

        y = ws[1] - y

        try:
            pixel = GL.glReadPixels(x, y, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT)
            newpoint = unproject(x, y, pixel[0])
        except Exception:
            return 0, 0, 0

        return newpoint 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:31,代码来源:camera.py

示例4: OnCaptureResult

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def OnCaptureResult(render_path, img_path, width, height, true_height, if_vis, render_type='rgb'):
    if render_type == 'rgb':
        rgb_img = GL.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, outputType=None)[::-1, :, :][
              height - true_height:, :, :]
        if if_vis:
            plt.imshow(rgb_img)
            plt.axis('off')
            plt.savefig(img_path, bbox_inches='tight')
            plt.close()
        # print render_path
        np.save(render_path, rgb_img)
        return rgb_img
    elif render_type == 'segmentation':
        segment = GL.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, outputType=None)[::-1, :, :][
              height - true_height:, :, 0]
        if if_vis:
            plt.imshow(segment, vmin=0, vmax=38)
            # plt.colorbar()
            plt.axis('off')
            plt.savefig(img_path, bbox_inches='tight')
            plt.close()
        np.save(render_path, segment)
        return segment
    elif render_type == 'normal':
        normal = GL.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, outputType=None)[::-1, :, :][
                 height - true_height:, :, :]
        if if_vis:
            plt.imshow(normal)
            plt.axis('off')
            plt.savefig(img_path, bbox_inches='tight')
            plt.close()
        np.save(render_path, normal)
        return normal
    elif render_type == 'depth':
        data = GL.glReadPixels(0, 0, width, height, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT,
                               outputType=None)  # read projected pixel info
        capturedImage = data
        for i in range(width):
            for j in range(height):
                if capturedImage[i][j] == 1.0:
                    capturedImage[i][j] = 20
                else:
                    far = FAR
                    near = 0.1
                    clip_z = (capturedImage[i][j] - 0.5) * 2.0
                    world_z = 2 * far * near / (clip_z * (far - near) - (far + near))
                    capturedImage[i][j] = -world_z  # -z#
        depth = capturedImage[::-1, :][height - true_height:, :]
        if if_vis:
            fig = plt.figure()
            ii = plt.imshow(depth, interpolation='nearest')
            # fig.colorbar(ii)
            plt.axis('off')
            plt.savefig(img_path, bbox_inches='tight')
            plt.close()
        np.save(render_path, depth)
        scipy.io.savemat(render_path + '.mat', mdict={'depth': depth})
        return depth 
开发者ID:thusiyuan,项目名称:holistic_scene_parsing,代码行数:60,代码来源:render_scene.py


注:本文中的OpenGL.GL.glReadPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。