blenderproc.python.loader.BopLoader module

class blenderproc.python.loader.BopLoader.BopLoader[source]

Bases: object

static _compute_camera_to_world_trafo(cam_H_m2w_ref, cam_H_m2c_ref, source_frame)[source]

Returns camera to world transformation in blender coords.

Parameters:
  • cam_H_m2c_ref (<built-in function array>) – (4x4) Homog trafo from object to camera coords.
  • cam_H_m2w_ref (<built-in function array>) – (4x4) Homog trafo from object to world coords.
  • source_frame (list) – Can be used if the given positions and rotations are specified in frames different from the blender frame.
Return type:

ndarray

Returns:

cam_H_c2w: (4x4) Homog trafo from camera to world coords.

static _get_loaded_obj(model_path)[source]

Returns the object if it has already been loaded.

Parameters:model_path (str) – Model path of the new object.
Return type:Object
Returns:Object if found, else return None.
static _get_ref_cam_extrinsics_intrinsics(sc_camera, cam_id, insts, scale)[source]

Get camK and transformation from object instance 0 to camera cam_id as reference.

Parameters:
  • sc_camera (dict) – BOP scene_camera file.
  • cam_id (int) – BOP camera id.
  • insts (dict) – Instance from BOP scene_gt file.
  • scale (float) – Factor to transform get pose in mm or meters.
Return (camK, cam_H_m2c_ref):
 

loaded camera matrix. Loaded object to camera transformation.

Return type:

ndarray

static _insert_key_frames(obj, frame_id)[source]

Insert key frames for given object pose.

Parameters:
  • obj (Object) – Loaded object.
  • frame_id (int) – The frame number where key frames should be inserted.
static _load_materials(cur_obj, bop_dataset_name)[source]

Loads / defines materials, e.g. vertex colors.

Parameters:
  • cur_obj (Object) – The object to use.
  • bop_dataset_name (str) – The name of the used bop dataset.
Return type:

Material

Returns:

Material with vertex color.

static _load_mesh(obj_id, model_p, bop_dataset_name, has_external_texture, temp_dir, allow_duplication, scale=1)[source]

Loads BOP mesh and sets category_id.

Parameters:
  • obj_id (int) – The obj_id of the BOP Object.
  • model_p (dict) – model parameters defined in dataset_params.py in bop_toolkit.
  • bop_dataset_name (str) – The name of the used bop dataset.
  • has_external_texture (bool) – Set to True, if the object has an external texture.
  • temp_dir (str) – A temp directory which is used for writing the temporary .ply file.
  • allow_duplication (bool) – If True, the object is duplicated if it already exists.
  • scale (float) – factor to transform set pose in mm or meters.
Return type:

MeshObject

Returns:

Loaded mesh object.

static _load_texture(cur_obj, texture_file_path, bop_dataset_name)[source]

Load the textures for the ycbv objects, only those contain texture information

Parameters:
  • cur_obj (Object) – The object to use.
  • texture_file_path (str) – path to the texture file (most likely “.png”)
  • bop_dataset_name (str) – The name of the used bop dataset.
static _setup_bop_toolkit(bop_dataset_path)[source]

Install the bop_toolkit from Github and set an environment variable pointing to the BOP datasets

Parameters:cam_H_m2c_ref – (4x4) Homog trafo from object to camera coords.
Return (bop_path, bop_dataset_name):
 Path to BOP datasets and BOP dataset name
Return type:tuple
static set_object_pose(cur_obj, inst, scale)[source]

Set object pose for current obj

Parameters:
  • cur_obj (Object) – Current object.
  • inst (dict) – instance from BOP scene_gt file.
  • scale (float) – factor to transform set pose in mm or meters.
blenderproc.python.loader.BopLoader.load_bop_intrinsics(bop_dataset_path, split='test', cam_type='')[source]

Load and set the camera matrix and image resolution of a specified BOP dataset

Parameters:
  • bop_dataset_path (str) – Full path to a specific bop dataset e.g. /home/user/bop/tless.
  • split (str) – Optionally, train, test or val split depending on BOP dataset, defaults to “test”
  • cam_type (str) – Camera type. If not defined, dataset-specific default camera type is used.
Return type:

tuple

Returns:

camera matrix K, W, H

blenderproc.python.loader.BopLoader.load_bop_objs(bop_dataset_path, model_type='', obj_ids=[], sample_objects=False, num_of_objs_to_sample=None, obj_instances_limit=-1, mm2m=False, move_origin_to_x_y_plane=False, temp_dir=None)[source]

Loads all or a subset of 3D models of any BOP dataset

Parameters:
  • bop_dataset_path (str) – Full path to a specific bop dataset e.g. /home/user/bop/tless.
  • model_type (str) – Optionally, specify type of BOP model. Available: [reconst, cad or eval].
  • obj_ids (list) – List of object ids to load. Default: [] (load all objects from the given BOP dataset)
  • sample_objects (bool) – Toggles object sampling from the specified dataset.
  • num_of_objs_to_sample (Optional[int]) – Amount of objects to sample from the specified dataset. If this amount is bigger than the dataset actually contains, then all objects will be loaded.
  • obj_instances_limit (int) – Limits the amount of object copies when sampling. Default: -1 (no limit).
  • mm2m (bool) – Specify whether to convert poses and models to meters.
  • move_origin_to_x_y_plane (bool) – Move center of the object to the lower side of the object, this will not work when used in combination with pose estimation tasks! This is designed for the use-case where BOP objects are used as filler objects in the background.
  • temp_dir (Optional[str]) – A temp directory which is used for writing the temporary .ply file.
Return type:

List[MeshObject]

Returns:

The list of loaded mesh objects.

blenderproc.python.loader.BopLoader.load_bop_scene(bop_dataset_path, scene_id, model_type='', cam_type='', split='test', source_frame=['X', '-Y', '-Z'], mm2m=False, temp_dir=None)[source]

Replicate a BOP scene from the given dataset: load scene objects, object poses, camera intrinsics and extrinsics

  • Interfaces with the bob_toolkit, allows loading of train, val and test splits
  • Relative camera poses are loaded/computed with respect to a reference model
  • Sets real camera intrinsics
Parameters:
  • bop_dataset_path (str) – Full path to a specific bop dataset e.g. /home/user/bop/tless.
  • scene_id (int) – Specify BOP dataset scene to synthetically replicate. Default: -1 (no scene is replicated, only BOP Objects are loaded).
  • model_type (str) – Optionally, specify type of BOP model. Available: [reconst, cad or eval].
  • cam_type (str) – Camera type. If not defined, dataset-specific default camera type is used.
  • split (str) – Optionally, test or val split depending on BOP dataset.
  • source_frame (list) – Can be used if the given positions and rotations are specified in frames different from the blender frame. Has to be a list of three strings. Example: [‘X’, ‘-Z’, ‘Y’]: Point (1,2,3) will be transformed to (1, -3, 2). Available: [‘X’, ‘Y’, ‘Z’, ‘-X’, ‘-Y’, ‘-Z’].
  • mm2m (bool) – Specify whether to convert poses and models to meters.
  • temp_dir (Optional[str]) – A temp directory which is used for writing the temporary .ply file.
Return type:

List[MeshObject]

Returns:

The list of loaded mesh objects.