ravens/environment.py
def render(self, config):
        """Render RGB-D image with specified configuration."""

        # Compute OpenGL camera settings.
        lookdir = np.array([0, 0, 1]).reshape(3, 1)
        updir = np.array([0, -1, 0]).reshape(3, 1)
        rotation = p.getMatrixFromQuaternion(config['rotation'])
        rotm = np.array(rotation).reshape(3, 3)
        lookdir = (rotm @ lookdir).reshape(-1)
        updir = (rotm @ updir).reshape(-1)
        lookat = config['position'] + lookdir
        focal_length = config['intrinsics'][0]
        znear, zfar = config['zrange']
        viewm = p.computeViewMatrix(config['position'], lookat, updir)
        fovh = (np.arctan((config['image_size'][0] /
                           2) / focal_length) * 2 / np.pi) * 180

        # Notes: 1) FOV is vertical FOV 2) aspect must be float
        aspect_ratio = config['image_size'][1] / config['image_size'][0]
        projm = p.computeProjectionMatrixFOV(fovh, aspect_ratio, znear, zfar)

        # Render with OpenGL camera settings.
        _, _, color, depth, segm = p.getCameraImage(
            width=config['image_size'][1],
            height=config['image_size'][0],
            viewMatrix=viewm,
            projectionMatrix=projm,
            shadow=1,
            flags=p.ER_SEGMENTATION_MASK_OBJECT_AND_LINKINDEX,
            renderer=p.ER_BULLET_HARDWARE_OPENGL)

        # Get color image.
        color_image_size = (config['image_size'][0],
                            config['image_size'][1], 4)
        color = np.array(color, dtype=np.uint8).reshape(color_image_size)
        color = color[:, :, :3]  # remove alpha channel
        color_image_size = (color_image_size[0], color_image_size[1], 3)
        if config['noise']:
            color = np.int32(color)
            color += np.int32(np.random.normal(0, 3, color_image_size))
            color = np.uint8(np.clip(color, 0, 255))

        # Get depth image.
        depth_image_size = (config['image_size'][0], config['image_size'][1])
        zbuffer = np.array(depth).reshape(depth_image_size)
        depth = (zfar + znear - (2. * zbuffer - 1.) * (zfar - znear))
        depth = (2. * znear * zfar) / depth
        if config['noise']:
            depth += np.random.normal(0, 0.003, depth_image_size)

        # Get segmentation image.
        segm = np.uint8(segm).reshape(depth_image_size)

        return color, depth, segm
Render RGB-D image with specified configuration.
Render RGB-D image with specified configuration.
Render RGB - D image with specified configuration .
def render(self, config):
        lookdir = np.array([0, 0, 1]).reshape(3, 1)
        updir = np.array([0, -1, 0]).reshape(3, 1)
        rotation = p.getMatrixFromQuaternion(config['rotation'])
        rotm = np.array(rotation).reshape(3, 3)
        lookdir = (rotm @ lookdir).reshape(-1)
        updir = (rotm @ updir).reshape(-1)
        lookat = config['position'] + lookdir
        focal_length = config['intrinsics'][0]
        znear, zfar = config['zrange']
        viewm = p.computeViewMatrix(config['position'], lookat, updir)
        fovh = (np.arctan((config['image_size'][0] /
                           2) / focal_length) * 2 / np.pi) * 180
        aspect_ratio = config['image_size'][1] / config['image_size'][0]
        projm = p.computeProjectionMatrixFOV(fovh, aspect_ratio, znear, zfar)
        _, _, color, depth, segm = p.getCameraImage(
            width=config['image_size'][1],
            height=config['image_size'][0],
            viewMatrix=viewm,
            projectionMatrix=projm,
            shadow=1,
            flags=p.ER_SEGMENTATION_MASK_OBJECT_AND_LINKINDEX,
            renderer=p.ER_BULLET_HARDWARE_OPENGL)
        color_image_size = (config['image_size'][0],
                            config['image_size'][1], 4)
        color = np.array(color, dtype=np.uint8).reshape(color_image_size)
        color = color[:, :, :3]  
        color_image_size = (color_image_size[0], color_image_size[1], 3)
        if config['noise']:
            color = np.int32(color)
            color += np.int32(np.random.normal(0, 3, color_image_size))
            color = np.uint8(np.clip(color, 0, 255))
        depth_image_size = (config['image_size'][0], config['image_size'][1])
        zbuffer = np.array(depth).reshape(depth_image_size)
        depth = (zfar + znear - (2. * zbuffer - 1.) * (zfar - znear))
        depth = (2. * znear * zfar) / depth
        if config['noise']:
            depth += np.random.normal(0, 0.003, depth_image_size)
        segm = np.uint8(segm).reshape(depth_image_size)
        return color, depth, segm
def render ( self , config ) : lookdir = np . array ( [ 0 , 0 , 1 ] ) . reshape ( 3 , 1 ) updir = np . array ( [ 0 , - 1 , 0 ] ) . reshape ( 3 , 1 ) rotation = p . getMatrixFromQuaternion ( config [ 'rotation' ] ) rotm = np . array ( rotation ) . reshape ( 3 , 3 ) lookdir = ( rotm @ lookdir ) . reshape ( - 1 ) updir = ( rotm @ updir ) . reshape ( - 1 ) lookat = config [ 'position' ] + lookdir focal_length = config [ 'intrinsics' ] [ 0 ] znear , zfar = config [ 'zrange' ] viewm = p . computeViewMatrix ( config [ 'position' ] , lookat , updir ) fovh = ( np . arctan ( ( config [ 'image_size' ] [ 0 ] / 2 ) / focal_length ) * 2 / np . pi ) * 180 aspect_ratio = config [ 'image_size' ] [ 1 ] / config [ 'image_size' ] [ 0 ] projm = p . computeProjectionMatrixFOV ( fovh , aspect_ratio , znear , zfar ) _ , _ , color , depth , segm = p . getCameraImage ( width = config [ 'image_size' ] [ 1 ] , height = config [ 'image_size' ] [ 0 ] , viewMatrix = viewm , projectionMatrix = projm , shadow = 1 , flags = p . ER_SEGMENTATION_MASK_OBJECT_AND_LINKINDEX , renderer = p . ER_BULLET_HARDWARE_OPENGL ) color_image_size = ( config [ 'image_size' ] [ 0 ] , config [ 'image_size' ] [ 1 ] , 4 ) color = np . array ( color , dtype = np . uint8 ) . reshape ( color_image_size ) color = color [ : , : , : 3 ] color_image_size = ( color_image_size [ 0 ] , color_image_size [ 1 ] , 3 ) if config [ 'noise' ] : color = np . int32 ( color ) color += np . int32 ( np . random . normal ( 0 , 3 , color_image_size ) ) color = np . uint8 ( np . clip ( color , 0 , 255 ) ) depth_image_size = ( config [ 'image_size' ] [ 0 ] , config [ 'image_size' ] [ 1 ] ) zbuffer = np . array ( depth ) . reshape ( depth_image_size ) depth = ( zfar + znear - ( 2. * zbuffer - 1. ) * ( zfar - znear ) ) depth = ( 2. * znear * zfar ) / depth if config [ 'noise' ] : depth += np . random . normal ( 0 , 0.003 , depth_image_size ) segm = np . uint8 ( segm ) . reshape ( depth_image_size ) return color , depth , segm
Render RGB-D image with specified configuration.
Render RGB - D image with specified configuration .
"""Render RGB-D image with specified configuration.""" # Compute OpenGL camera settings. # Notes: 1) FOV is vertical FOV 2) aspect must be float # Render with OpenGL camera settings. # Get color image. # remove alpha channel # Get depth image. # Get segmentation image.
self
config