Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(TestGradients, self).__init__(*args, **kwargs)
        sl.init()
        self.scene = sl.Scene((640, 480))

        # Taken from first YCB frame
        # NOTE: This is not constant throughout the real dataset!
        fx, fy, cx, cy = 1066.778, 1067.487, 312.9869, 241.3109
        self.scene.set_camera_intrinsics(fx, fy, cx, cy)

        mesh_files = [os.path.join(TESTS_PATH, 'stanford_bunny', 'scene.gltf')]
        self.meshes = []
        for mesh_file in mesh_files:
            mesh = sl.Mesh(mesh_file)

            print("Loaded mesh with bounding box:", mesh.bbox)
            print("center:", mesh.bbox.center, "size:", mesh.bbox.size)

            mesh.center_bbox()
            mesh.scale_to_bbox_diagonal(0.5, 'order_of_magnitude')

            print("normalized:", mesh.bbox)
            print("center:", mesh.bbox.center, "size:", mesh.bbox.size,
                  "diagonal:", mesh.bbox.diagonal)
            self.meshes.append(mesh)
Ejemplo n.º 2
0
def run(ycb_path, ibl_path, plane_texture_path):
    mesh_path = pathlib.Path(ycb_path) / 'models'
    if ibl_path:
        ibl_path = pathlib.Path(ibl_path)

    sl.init()  # use sl.init_cuda() for CUDA interop

    # Load all meshes
    meshes = sl.Mesh.load_threaded(
        [mesh_path / c / 'textured.obj' for c in CLASSES[1:]])

    # Setup class IDs
    for i, mesh in enumerate(meshes):
        mesh.class_index = i + 1

    # Create a scene with matching intrinsics
    scene = sl.Scene(RESOLUTION)
    scene.set_camera_intrinsics(*INTRINSICS)

    for mesh in random.sample(meshes, 10):
        obj = sl.Object(mesh)

        # Override the metallic/roughness parameters so that it gets interesting
        obj.metallic = random.random()
        obj.roughness = random.random()
        scene.add_object(obj)

    # Let them fall in a heap
    scene.simulate_tabletop_scene()

    # Setup lighting
    if ibl_path:
        scene.light_map = sl.LightMap(ibl_path)
    else:
        scene.choose_random_light_position()

    # Display a plane & set background color
    scene.background_plane_size = torch.tensor([3.0, 3.0])
    scene.background_color = torch.tensor([0.1, 0.1, 0.1, 1.0])

    if plane_texture_path:
        scene.background_plane_texture = sl.Texture2D(plane_texture_path)

    # Display interactive viewer
    sl.view(scene)

    # Render a frame
    renderer = sl.RenderPass()
    result = renderer.render(scene)

    # Save as JPEG
    Image.fromarray(result.rgb()[:, :, :3].cpu().numpy()).save('rgb.jpeg')
Ejemplo n.º 3
0
    def test_render(self):
        scene = sl.Scene((640, 480))

        with Timer('Mesh load'):
            mesh = sl.Mesh(
                os.path.join(TESTS_PATH, 'stanford_bunny', 'scene.gltf'))
        mesh.center_bbox()
        mesh.scale_to_bbox_diagonal(0.5)
        object = sl.Object(mesh)

        scene.add_object(object)

        pose = torch.eye(4)
        pose[2, 3] = 0.5
        object.set_pose(pose)

        with Timer('render'):
            renderer = sl.RenderPass()
            result = renderer.render(scene)

        with Timer('retrieve'):
            rgb = result.rgb()

        print("First pixel:", rgb[0, 0])
        print("min: {}, max: {}".format(rgb.min(), rgb.max()))

        rgb_np = rgb.cpu().numpy()

        img = Image.fromarray(rgb_np, mode='RGBA')
        img.save('/tmp/stillleben.png')

        dbg = sl.render_debug_image(scene)
        dbg_np = dbg.cpu().numpy()

        dbg_img = Image.fromarray(dbg_np, mode='RGBA')
        dbg_img.save('/tmp/stillleben_debug.png')

        rgb_noise = process_image(rgb.permute(2, 0, 1)[:3].float() / 255.0)
        rgb_noise_np = (rgb_noise * 255).byte().permute(
            1, 2, 0).contiguous().cpu().numpy()
        noise_img = Image.fromarray(rgb_noise_np, mode='RGB')
        noise_img.save('/tmp/stillleben_noise.png')
Ejemplo n.º 4
0
import stillleben as sl
import torch
import random
from PIL import Image

sl.init()  # use sl.init_cuda() for CUDA interop

# Load a mesh (the constructor accepts pathlib paths)
mesh = sl.Mesh(SL_PATH / 'tests' / 'stanford_bunny' / 'scene.gltf')

# Meshes can come in strange dimensions - rescale to something reasonable
mesh.scale_to_bbox_diagonal(0.5)

# Create a scene with a few bunnies
scene = sl.Scene((1920, 1080))

for i in range(20):
    obj = sl.Object(mesh)

    # Override the metallic/roughness parameters so that it gets interesting
    obj.metallic = random.random()
    obj.roughness = random.random()
    scene.add_object(obj)

# Let them fall in a heap
scene.simulate_tabletop_scene()

# Setup lighting
scene.light_map = sl.LightMap(SL_PATH / 'examples' / 'Circus_Backstage' /
                              'Circus_Backstage.ibl')
Ejemplo n.º 5
0
                        type=str,
                        default='0,0',
                        help='Background plane size')
    parser.add_argument('--background-plane-texture',
                        type=str,
                        help='Background plane texture')

    parser.add_argument('--tabletop-video',
                        type=str,
                        help='Write tabletop video to this location')

    args = parser.parse_args()

    sl.init()

    scene = sl.Scene([int(d) for d in args.size.split('x')])

    if args.background:
        scene.background_image = sl.Texture(args.background)

    scene.background_color = torch.tensor(
        [float(a) for a in args.background_color.split(',')])

    print('Loading meshes (this can take some time)...')
    meshes = sl.Mesh.load_threaded(args.mesh)
    for mesh in meshes:
        print("Loaded mesh with bounding box:", mesh.bbox)
        print("center:", mesh.bbox.center, "size:", mesh.bbox.size)

        if args.normalize:
            mesh.center_bbox()