Пример #1
0
    def __init__(self,
                 env,
                 img_path='images/',
                 width=500,
                 height=500,
                 spp=256,
                 use_noise=False,
                 debug_mode=False,
                 video_mode=False,
                 video_path='videos/',
                 video_name='robosuite_video_0.mp4',
                 video_fps=60,
                 verbose=1,
                 vision_modalities=None):
        """
        Initializes the nvisii wrapper. Wrapping any MuJoCo environment in this 
        wrapper will use the NVISII wrapper for rendering.

        Args:
            env (MujocoEnv instance): The environment to wrap.

            img_path (string): Path to images.

            width (int, optional): Width of the rendered image. Defaults to 500.

            height (int, optional): Height of the rendered image. Defaults to 500.

            spp (int, optional): Sample-per-pixel for each image. Larger spp will result
                                 in higher quality images but will take more time to render
                                 each image. Higher quality images typically use an spp of
                                 around 512.

            use_noise (bool, optional): Use noise or denoise. Deafults to false.

            debug_mode (bool, optional): Use debug mode for nvisii. Deafults to false.

            video_mode (bool, optional): By deafult, the NVISII wrapper saves the results as 
                                         images. If video_mode is set to true, a video is
                                         produced and will be stored in the directory defined
                                         by video_path. Defaults to false.
            
            video_path (string, optional): Path to store the video. Required if video_mode is 
                                           set to true. Defaults to 'videos/'.

            video_name (string, optional): Name for the file for the video. Defaults to
                                           'robosuite_video_0.mp4'.
            
            video_fps (int, optional): Frames per second for video. Defaults to 60.

            verbose (int, optional): If verbose is set to 1, the wrapper will print the image
                                     number for each image rendered. If verbose is set to 0, 
                                     nothing will be printed. Defaults to 1.

            vision_modalities (string, optional): Options to render image with different ground truths
                                              for NVISII. Options include "normal", "texture_coordinates",
                                              "position", "depth".
        """

        super().__init__(env, renderer_type="nvisii")

        self.env = env
        self.img_path = img_path
        self.width = width
        self.height = height
        self.spp = spp
        self.use_noise = use_noise

        self.video_mode = video_mode
        self.video_path = video_path
        self.video_name = video_name
        self.video_fps = video_fps

        self.verbose = verbose
        self.vision_modalities = vision_modalities

        self.img_cntr = 0

        env._setup_references()

        # enable interactive mode when debugging
        if debug_mode:
            nvisii.initialize_interactive()
        else:
            nvisii.initialize(headless=True)

        self.segmentation_type = self.env.camera_segmentations

        # add denoiser to nvisii if not using noise
        if not use_noise:
            nvisii.configure_denoiser()
            nvisii.enable_denoiser()
            nvisii.configure_denoiser(True, True, False)

        if not os.path.exists(img_path):
            os.makedirs(img_path)

        if video_mode:
            if not os.path.exists(video_path):
                os.makedirs(video_path)
            self.video = cv2.VideoWriter(video_path + video_name,
                                         cv2.VideoWriter_fourcc(*'MP4V'),
                                         video_fps, (self.width, self.height))
            print(f'video mode enabled')

        if vision_modalities is None and self.segmentation_type[0] == None:
            nvisii.sample_pixel_area(x_sample_interval=(0.0, 1.0),
                                     y_sample_interval=(0.0, 1.0))
        else:
            nvisii.sample_pixel_area(x_sample_interval=(0.5, 0.5),
                                     y_sample_interval=(0.5, 0.5))

        self._init_nvisii_components()
Пример #2
0
import nvisii

opt = lambda: None
opt.nb_objects = 50
opt.spp = 256
opt.width = 500
opt.height = 500
opt.out = "04_load_obj_file.png"

# # # # # # # # # # # # # # # # # # # # # # # # #
nvisii.initialize(headless=True, verbose=True)

nvisii.enable_denoiser()

camera = nvisii.entity.create(name="camera",
                              transform=nvisii.transform.create("camera"),
                              camera=nvisii.camera.create(
                                  name="camera",
                                  aspect=float(opt.width) / float(opt.height)))

camera.get_transform().look_at(
    at=(0, 0.1, 0.1),
    up=(0, 0, 1),
    eye=(1, 0.7, 0.2),
)
nvisii.set_camera_entity(camera)

nvisii.set_dome_light_sky(sun_position=(10, 10, 1), saturation=2)
nvisii.set_dome_light_exposure(1)

# # # # # # # # # # # # # # # # # # # # # # # # #
Пример #3
0
import pybullet as p
import time
import math
import time

import nvisii as nv
nv.initialize(window_on_top=True)

camera = nv.entity.create(name="camera",
                          camera=nv.camera.create("camera"),
                          transform=nv.transform.create("camera"))
nv.set_camera_entity(camera)

nv.enable_denoiser()
nv.disable_dome_light_sampling()

nv.set_dome_light_color((0, 0, 0))
light = nv.entity.create(name="light",
                         transform=nv.transform.create("light"),
                         mesh=nv.mesh.create_plane("light", flip_z=True),
                         light=nv.light.create("light"))
light.get_transform().set_position((0, 0, 1.5))
light.get_transform().set_scale((.25, .25, .25))
light.get_light().set_temperature(4500)
light.get_light().set_exposure(2)

# Enable nvisii interactions
camera.get_transform().look_at(eye=(-2., 2., .4), at=(0, 0, .4), up=(0, 0, 1))
cursor = nv.vec4()
speed_camera = .20
rot = nv.vec2(0, 0)