Esempio n. 1
0
        for obj_id in dp_model['obj_ids']:
            models[obj_id] = inout.load_ply(
                dp_model['model_tpath'].format(obj_id=obj_id))

    # Load models info.
    models_info = None
    if p['error_type'] in ['ad', 'add', 'adi', 'vsd', 'mssd', 'mspd', 'cus']:
        models_info = inout.load_json(dp_model['models_info_path'],
                                      keys_to_int=True)

    # Get sets of symmetry transformations for the object models.
    models_sym = None
    if p['error_type'] in ['mssd', 'mspd']:
        models_sym = {}
        for obj_id in dp_model['obj_ids']:
            models_sym[obj_id] = misc.get_symmetry_transformations(
                models_info[obj_id], p['max_sym_disc_step'])

    # Initialize a renderer.
    ren = None
    if p['error_type'] in ['vsd', 'cus']:
        misc.log('Initializing renderer...')
        width, height = dp_split['im_size']
        ren = renderer.create_renderer(width,
                                       height,
                                       p['renderer_type'],
                                       mode='depth')
        for obj_id in dp_model['obj_ids']:
            ren.add_object(obj_id,
                           dp_model['model_tpath'].format(obj_id=obj_id))

    # Load the estimation targets.
Esempio n. 2
0
def init(target):
    """
    Initialize scene for given [target] object to evaluate pose-error functions. Prepare rendering and evaluation.
    """

    renderer = RendererPython(640, 480, bg_color=(1.0, 1.0, 1.0, 1.0), shading='flat')

    # base scene (static support)
    ground_volume = resource.get(f"{DATA_PATH}/cube.ply").convert('VolumeGrid')
    renderer.add_object(0, f"{DATA_PATH}/cube.ply")

    env = [ground_volume]
    env_meshes = [trimesh.load(f"{DATA_PATH}/cube.ply")]
    env_ids = [0]
    env_Ts = [np.eye(4)]

    # initialize remaining scene objects based on target object
    Tgt = np.eye(4)
    if target == 'bowl':
        # bowl
        obj_id = 13
        cloud, ply, mesh = get_tgt_model(obj_id, renderer)
        Tgt[:3, 3] = np.array([0, 0, -models_info[obj_id]['min_z'] - obj_toff[obj_id - 1][2]])
        t_obj_offset = [-125, 0, 0]
    elif target == 'marker':
        # marker
        obj_id = 18
        cloud, ply, mesh = get_tgt_model(obj_id, renderer)
        Tgt[:3, :3] = Rotation.from_euler('xz', [21.5, 90.0], degrees=True).as_dcm()
        Tgt[:3, 3] = [33.42, 0, 30.14]
        t_obj_offset = [-300, 25, 50]

        # banana
        env_model, env_mesh = get_env_model(10, renderer)
        T = np.eye(4)
        T[:3, :3] = Rotation.from_euler('xyz', [0, 11.8, 0], degrees=True).as_dcm()
        T[:3, 3] = [0, 0, 16]
        env_mesh.apply_transform(T)

        env.append(env_model)
        env_meshes.append(env_mesh)
        env_ids.append(-10)
        env_Ts.append(T.copy())
    elif target == 'clamp':
        # clamp
        obj_id = 19
        cloud, ply, mesh = get_tgt_model(obj_id, renderer)
        Tgt[:3, :3] = Rotation.from_euler('xyz', [-6, -1.4, -90], degrees=True).as_dcm()
        Tgt[:3, 3] = [9.59, 0, 91.74]
        t_obj_offset = [-150, 0, 65]

        # pudding
        env_model, env_mesh = get_env_model(7, renderer)
        T = np.eye(4)
        T[:3, :3] = Rotation.from_euler('xyz', [-88.4, 0.4, 90], degrees=True).as_dcm()
        T[:3, 3] = [-61.66, 1.24, 44.27]
        env_mesh.apply_transform(T)

        env.append(env_model)
        env_meshes.append(env_mesh)
        env_ids.append(-7)
        env_Ts.append(T.copy())

        # jello
        env_model, env_mesh = get_env_model(8, renderer)
        T = np.eye(4)
        T[:3, :3] = Rotation.from_euler('xyz', [-90, 90, 180], degrees=True).as_dcm()
        T[:3, 3] = [74.90, -1.09, 36.37]
        env_mesh.apply_transform(T)

        env.append(env_model)
        env_meshes.append(env_mesh)
        env_ids.append(-8)
        env_Ts.append(T.copy())
    else:
        raise ValueError("'target' must be one of 'bowl', 'marker' or 'clamp'.")
    Tsyms = misc.get_symmetry_transformations(models_info[obj_id], 0.01)  # symmetry

    # prepare renderer: intrinsics and extrinsics
    K = np.array([1066.778, 0.0, 312.9869, 0.0, 1067.487, 241.3109, 0.0, 0.0, 1.0]).reshape(3, 3)
    Rview = Rotation.from_euler('zx', [-90 if target == 'bowl' else 0, 90 if target == 'bowl' else 110],
                                degrees=True).as_dcm()
    tview = np.array([-t_obj_offset[1], t_obj_offset[2], 850+t_obj_offset[0]])

    return env_meshes, env, env_ids, env_Ts, mesh, cloud, ply, Tgt, Tsyms, renderer, K, Rview, tview