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


Python GL.GL_RGB属性代码示例

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


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

示例1: render

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGB [as 别名]
def render(self, pixmap, viewport_shape):
    """Renders the pixmap on a fullscreen quad.

    Args:
      pixmap: A 3D numpy array of bytes (np.uint8), with dimensions
        (width, height, 3).
      viewport_shape: A tuple of two elements, (width, height).
    """
    GL.glClear(GL.GL_COLOR_BUFFER_BIT)
    GL.glViewport(0, 0, *viewport_shape)
    GL.glUseProgram(self._shader)
    GL.glActiveTexture(GL.GL_TEXTURE0)
    GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture)
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, pixmap.shape[1],
                    pixmap.shape[0], 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE,
                    pixmap)
    GL.glUniform1i(self._var_texture_sampler, 0)
    GL.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4) 
开发者ID:deepmind,项目名称:dm_control,代码行数:21,代码来源:fullscreen_quad.py

示例2: finish

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGB [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: fillTexture2d

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGB [as 别名]
def fillTexture2d(data,tex = None, interp=True):
    """ data.shape == (Ny,Nx)
          file texture with GL_RED
        data.shape == (Ny,Nx,3)
          file texture with GL_RGB

        if tex == None, returns a new created texture
    """

    if tex is None:
        tex = GL.glGenTextures(1)

    GL.glBindTexture(GL.GL_TEXTURE_2D, tex)
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT,1)
    GL.glTexParameterf (GL.GL_TEXTURE_2D,
                     GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
    GL.glTexParameterf (GL.GL_TEXTURE_2D,
                     GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR if interp else GL.GL_NEAREST)

    GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE)
    GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE)
    # GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP)
    # GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP)

    if data.ndim == 2:
        Ny,Nx = data.shape
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, Nx, Ny,
                     0, GL.GL_RED, GL.GL_FLOAT, data.astype(np.float32))

    elif data.ndim == 3 and data.shape[2]==3:
        Ny,Nx = data.shape[:2]
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, Nx, Ny,
                         0, GL.GL_RGB, GL.GL_FLOAT, data.astype(np.float32))

    elif data.ndim == 3 and data.shape[2]==4:
        Ny,Nx = data.shape[:2]
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, Nx, Ny,
                         0, GL.GL_RGBA, GL.GL_FLOAT, data.astype(np.float32))

    else:
        raise Exception("data format not supported! \ndata.shape should be either (Ny,Nx) or (Ny,Nx,3)")
    return tex 
开发者ID:maweigert,项目名称:spimagine,代码行数:44,代码来源:gui_utils.py

示例4: main

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGB [as 别名]
def main():
    # Create OpenGL window in single line
    pangolin.CreateWindowAndBind('Main', 640, 480)

    # 3D Mouse handler requires depth testing to be enabled
    gl.glEnable(gl.GL_DEPTH_TEST)


    scam = pangolin.OpenGlRenderState(
        pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000),
        pangolin.ModelViewLookAt(-1, 1, -1, 0, 0, 0, pangolin.AxisDirection.AxisY))

    # Aspect ratio allows us to constrain width and height whilst fitting within specified
    # bounds. A positive aspect ratio makes a view 'shrink to fit' (introducing empty bars),
    # whilst a negative ratio makes the view 'grow to fit' (cropping the view).
    dcam = pangolin.CreateDisplay()
    dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0/480.0)
    dcam.SetHandler(pangolin.Handler3D(scam))

    # This view will take up no more than a third of the windows width or height, and it
    # will have a fixed aspect ratio to match the image that it will display. When fitting
    # within the specified bounds, push to the top-left (as specified by SetLock).
    dimg = pangolin.Display('image')
    dimg.SetBounds(2./3, 1.0, 0.0, 1./3, 640./480)
    dimg.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop)


    w, h = 64, 48
    texture = pangolin.GlTexture(w, h, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)

    # Default hooks for exiting (Esc) and fullscreen (tab).
    while not pangolin.ShouldQuit():
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glClearColor(0.95, 0.95, 0.95, 1.0)

        dcam.Activate(scam)
        gl.glColor3f(1.0, 1.0, 1.0)
        pangolin.glDrawColouredCube()

        # Set some random image data and upload to GPU 
        image = random_image(w, h)
        texture.Upload(image, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)

        # display the image
        dimg.Activate()
        gl.glColor3f(1.0, 1.0, 1.0)
        texture.RenderToViewport()

        pangolin.FinishFrame() 
开发者ID:luigifreda,项目名称:pyslam,代码行数:51,代码来源:simpleDisplayImage.py

示例5: OnCaptureResult

# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGB [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.GL_RGB属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。