blenderproc.python.writer.BopWriterUtility module¶
-
class
blenderproc.python.writer.BopWriterUtility.
BopWriterUtility
[source]¶ Bases:
object
Saves the synthesized dataset in the BOP format. The dataset is split into chunks which are saved as individual “scenes”. For more details about the BOP format, visit the BOP toolkit docs: https://github.com/thodan/bop_toolkit/blob/master/docs/bop_datasets_format.md
-
static
_get_frame_camera
(save_world2cam, depth_scale=1.0, unit_scaling=1000.0, destination_frame=['X', '-Y', '-Z'])[source]¶ Returns camera parameters for the active camera. :param save_world2cam: If true, camera to world transformations “cam_R_w2c”, “cam_t_w2c” are saved in scene_camera.json :param depth_scale: Multiply the uint16 output depth image with this factor to get depth in mm. :param unit_scaling: 1000. for outputting poses in mm :param destination_frame: Transform poses from Blender internal coordinates to OpenCV coordinates :return: dict containing info for scene_camera.json
-
static
_get_frame_gt
(dataset_objects, unit_scaling, ignore_dist_thres, destination_frame=['X', '-Y', '-Z'])[source]¶ Returns GT pose annotations between active camera and objects. :type dataset_objects:
List
[Mesh
] :param dataset_objects: Save annotations for these objects. :type unit_scaling:float
:param unit_scaling: 1000. for outputting poses in mm :type ignore_dist_thres:float
:param ignore_dist_thres: Distance between camera and object after which object is ignored. Mostly due to failed physics. :type destination_frame:List
[str
] :param destination_frame: Transform poses from Blender internal coordinates to OpenCV coordinates :return: A list of GT camera-object pose annotations for scene_gt.json
-
static
_load_json
(path, keys_to_int=False)[source]¶ Loads content of a JSON file. From the BOP toolkit (https://github.com/thodan/bop_toolkit).
Parameters: - path – Path to the JSON file.
- keys_to_int – Convert digit dict keys to integers. Default: False
Returns: Content of the loaded JSON file.
-
static
_save_depth
(path, im)[source]¶ Saves a depth image (16-bit) to a PNG file. From the BOP toolkit (https://github.com/thodan/bop_toolkit).
Parameters: - path – Path to the output depth image file.
- im – ndarray with the depth image to save.
-
static
_save_json
(path, content)[source]¶ Saves the content to a JSON file in a human-friendly format. From the BOP toolkit (https://github.com/thodan/bop_toolkit).
Parameters: - path – Path to the output JSON file.
- content – Dictionary/list to save.
-
static
_write_camera
(camera_path, depth_scale=1.0)[source]¶ Writes camera.json into dataset_dir. :type camera_path:
str
:param camera_path: Path to camera.json :type depth_scale:float
:param depth_scale: Multiply the uint16 output depth image with this factor to get depth in mm.
-
static
_write_frames
(chunks_dir, dataset_objects, depths=[], colors=[], color_file_format='PNG', depth_scale=1.0, frames_per_chunk=1000, m2mm=True, ignore_dist_thres=100.0, save_world2cam=True, jpg_quality=95)[source]¶ Write each frame’s ground truth into chunk directory in BOP format
Parameters: - chunks_dir (
str
) – Path to the output directory of the current chunk. - dataset_objects (
list
) – Save annotations for these objects. - depths (
List
[ndarray
]) – List of depth images in m to save - colors (
List
[ndarray
]) – List of color images to save - color_file_format (
str
) – File type to save color images. Available: “PNG”, “JPEG” - jpg_quality (
int
) – If color_file_format is “JPEG”, save with the given quality. - depth_scale (
float
) – Multiply the uint16 output depth image with this factor to get depth in mm. Used to trade-off between depth accuracy and maximum depth value. Default corresponds to 65.54m maximum depth and 1mm accuracy. - ignore_dist_thres (
float
) – Distance between camera and object after which object is ignored. Mostly due to failed physics. - m2mm (
bool
) – Original bop annotations and models are in mm. If true, we convert the gt annotations to mm here. This is needed if BopLoader option mm2m is used. - frames_per_chunk (
int
) – Number of frames saved in each chunk (called scene in BOP)
- chunks_dir (
-
static
-
blenderproc.python.writer.BopWriterUtility.
write_bop
(output_dir, target_objects=None, depths=None, colors=None, color_file_format='PNG', dataset='', append_to_existing_output=True, depth_scale=1.0, jpg_quality=95, save_world2cam=True, ignore_dist_thres=100.0, m2mm=True, frames_per_chunk=1000)[source]¶ Write the BOP data
Parameters: - output_dir (
str
) – Path to the output directory. - target_objects (
Optional
[List
[MeshObject
]]) – Objects for which to save ground truth poses in BOP format. Default: Save all objects or from specified dataset - depths (
Optional
[List
[ndarray
]]) – List of depth images in m to save - colors (
Optional
[List
[ndarray
]]) – List of color images to save - color_file_format (
str
) – File type to save color images. Available: “PNG”, “JPEG” - jpg_quality (
int
) – If color_file_format is “JPEG”, save with the given quality. - dataset (
str
) – Only save annotations for objects of the specified bop dataset. Saves all object poses if undefined. - append_to_existing_output (
bool
) – If true, the new frames will be appended to the existing ones. - depth_scale (
float
) – Multiply the uint16 output depth image with this factor to get depth in mm. Used to trade-off between depth accuracy and maximum depth value. Default corresponds to 65.54m maximum depth and 1mm accuracy. - save_world2cam (
bool
) – If true, camera to world transformations “cam_R_w2c”, “cam_t_w2c” are saved in scene_camera.json - ignore_dist_thres (
float
) – Distance between camera and object after which object is ignored. Mostly due to failed physics. - m2mm (
bool
) – Original bop annotations and models are in mm. If true, we convert the gt annotations to mm here. This is needed if BopLoader option mm2m is used. - frames_per_chunk (
int
) – Number of frames saved in each chunk (called scene in BOP)
- output_dir (