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=True, frames_per_chunk=1000)

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)
blenderproc.writer.write_coco_annotations(output_dir, instance_segmaps=None, instance_attribute_maps=None, colors=None, color_file_format='PNG', mask_encoding_format='rle', supercategory='coco_annotations', append_to_existing_output=True, segmap_output_key='segmap', segcolormap_output_key='segcolormap', rgb_output_key='colors', jpg_quality=95, label_mapping=None, file_prefix='')

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 (Optional[List[ndarray]]) – List of instance segmentation maps
  • instance_attribute_maps (Optional[List[dict]]) – per-frame mappings with idx, class and optionally supercategory/bop_dataset_name
  • colors (Optional[List[ndarray]]) – List of color images
  • 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.
  • segmap_output_key (str) – The output key with which the segmentation images were registered. Should be the same as the output_key of the SegMapRenderer module. Default: segmap.
  • segcolormap_output_key (str) – The output key with which the csv file for object name/class correspondences was registered. Should be the same as the colormap_output_key of the SegMapRenderer module. Default: segcolormap.
  • rgb_output_key (str) – The output key with which the rgb images were registered. Should be the same as the output_key of the RgbRenderer module. Default: colors.
  • 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
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.