blenderproc.writer package

Module contents

blenderproc.writer.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=None, annotation_unit='mm', frames_per_chunk=1000, calc_mask_info_coco=True, delta=0.015, num_worker=None)

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 (Optional[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 (deprecated).

  • annotation_unit (str) – The unit in which the annotations are saved. Available: ‘m’, ‘dm’, ‘cm’, ‘mm’.

  • frames_per_chunk (int) – Number of frames saved in each chunk (called scene in BOP)

  • calc_mask_info_coco (bool) – Whether to calculate gt masks, gt info and gt coco annotations.

  • delta (float) – Tolerance used for estimation of the visibility masks (in [m]).

  • num_worker (Optional[int]) – The number of processes to use to calculate gt_masks and gt_info. If None is given, number of cores is used.

blenderproc.writer.write_coco_annotations(output_dir, instance_segmaps, instance_attribute_maps, colors, color_file_format='PNG', mask_encoding_format='rle', supercategory='coco_annotations', append_to_existing_output=True, jpg_quality=95, label_mapping=None, file_prefix='', indent=None)

Writes coco annotations in the following steps: 1. Locate the seg images 2. Locate the rgb maps 3. Locate the seg mappings 4. Read color mappings 5. For each frame write the coco annotation

Parameters:
  • output_dir (str) – Output directory to write the coco annotations

  • instance_segmaps (List[ndarray]) – List of instance segmentation maps

  • instance_attribute_maps (List[dict]) – per-frame mappings with idx, class and optionally supercategory/bop_dataset_name

  • colors (List[ndarray]) – List of color images. Does not support stereo images, enter left and right inputs subsequently.

  • color_file_format (str) – Format to save color images in

  • mask_encoding_format (str) – Encoding format of the binary masks. Default: ‘rle’. Available: ‘rle’, ‘polygon’.

  • supercategory (str) – name of the dataset/supercategory to filter for, e.g. a specific BOP dataset set by ‘bop_dataset_name’ or any loaded object with specified ‘cp_supercategory’

  • append_to_existing_output (bool) – If true and if there is already a coco_annotations.json file in the output directory, the new coco annotations will be appended to the existing file. Also, the rgb images will be named such that there are no collisions.

  • jpg_quality (int) – The desired quality level of the jpg encoding

  • label_mapping (Optional[LabelIdMapping]) – The label mapping which should be used to label the categories based on their ids. If None, is given then the name field in the csv files is used or - if not existing - the category id itself is used.

  • file_prefix (str) – Optional prefix for image file names

  • indent (Union[int, str, None]) – If indent is a non-negative integer or string, then the annotation output will be pretty-printed with that indent level. An indent level of 0, negative, or “” will only insert newlines. None (the default) selects the most compact representation. Using a positive integer indent indents that many spaces per level. If indent is a string (such as “ “), that string is used to indent each level.

blenderproc.writer.write_gif_animation(output_dir_path, output_data_dict, append_to_existing_output=False, frame_duration_in_ms=50, reverse_animation=False)

Generates a .gif file animation out of rendered frames

Parameters:
  • output_dir_path (str) – The directory path in which the gif animation folder will be saved

  • output_data_dict (Dict[str, List[Union[ndarray, list, dict]]]) – The data dictionary which was produced by the render method.

  • append_to_existing_output (bool) – If this is True, the output_dir_path folder will be scanned for pre-existing files of the name #_animation.gif and the number of newly added files will start right where the last run left off.

  • frame_duration_in_ms (int) – Duration of each frame in the animation in milliseconds.

  • reverse_animation (bool) – If this is True, the order of the frames will be reversed.

blenderproc.writer.write_hdf5(output_dir_path, output_data_dict, append_to_existing_output=False, stereo_separate_keys=False)

Saves the information provided inside of the output_data_dict into a .hdf5 container

Parameters:
  • output_dir_path (str) – The folder path in which the .hdf5 containers will be generated

  • output_data_dict (Dict[str, List[Union[ndarray, list, dict]]]) – The container, which keeps the different images, which should be saved to disc. Each key will be saved as its own key in the .hdf5 container.

  • append_to_existing_output (bool) – If this is True, the output_dir_path folder will be scanned for pre-existing .hdf5 containers and the numbering of the newly added containers, will start right where the last run left off.

  • stereo_separate_keys (bool) – If this is True and the rendering was done in stereo mode, than the stereo images won’t be saved in one tensor [2, img_x, img_y, channels], where the img[0] is the left image and img[1] the right. They will be saved in separate keys: for example for colors in colors_0 and colors_1.