blenderproc.python.loader.BopLoader module
Provides functions to load the objects inside the bop dataset.
- class blenderproc.python.loader.BopLoader._BopLoader[source]
Bases:
object
- CACHED_OBJECTS = {}
- 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 (
array
) – (4x4) Homog trafo from object to camera coords.cam_H_m2w_ref (
array
) – (4x4) Homog trafo from object to world coords.source_frame (
List
[str
]) – 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:
Optional
[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:
Tuple
[ndarray
,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_mesh(obj_id, model_p, bop_dataset_name, 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.scale (
float
) – factor to transform set pose in mm or meters.
- Return type:
- Returns:
Loaded mesh object.
- 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.
- 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:
bop_dataset_path (
str
) – Path to the bop dataset- Return (bop_path, bop_dataset_name):
Path to BOP datasets and BOP dataset name
- Return type:
Tuple
[str
,str
]
- 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
[ndarray
,int
,int
]- Returns:
camera matrix K, W, H
- blenderproc.python.loader.BopLoader.load_bop_objs(bop_dataset_path, model_type='', obj_ids=None, sample_objects=False, num_of_objs_to_sample=None, obj_instances_limit=-1, mm2m=None, object_model_unit='m', move_origin_to_x_y_plane=False)[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 (
Optional
[List
[int
]]) – 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 (
Optional
[bool
]) – Specify whether to convert poses and models to meters (deprecated).object_model_unit (
str
) – The unit the object model is in. Object model will be scaled to meters. This does not affect the annotation units. Available: [‘m’, ‘dm’, ‘cm’, ‘mm’].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.
- 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=None, mm2m=None, object_model_unit='m')[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 (
Optional
[List
[str
]]) – 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). Default: [“X”, “-Y”, “-Z”], Available: [‘X’, ‘Y’, ‘Z’, ‘-X’, ‘-Y’, ‘-Z’].mm2m (
Optional
[bool
]) – Specify whether to convert poses and models to meters (deprecated).object_model_unit (
str
) – The unit the object model is in. Object model will be scaled to meters. This does not affect the annotation units. Available: [‘m’, ‘dm’, ‘cm’, ‘mm’].
- Return type:
List
[MeshObject
]- Returns:
The list of loaded mesh objects.