blenderproc.python.writer.WriterUtility module

Provides functionality to write the generated data to disc.

class blenderproc.python.writer.WriterUtility._WriterUtility[source]

Bases: object

static _get_shapenet_attribute(shapenet_obj, attribute_name, local_frame_change=None, world_frame_change=None)[source]

Returns the value of the requested attribute for the given object.

Parameters:
  • shapenet_obj (Object) – The ShapeNet object.

  • attribute_name (str) – The attribute name.

  • local_frame_change (Optional[List[str]]) – Can be used to change the local coordinate frame of matrices. Default: [“X”, “Y”, “Z”]

  • world_frame_change (Optional[List[str]]) – Can be used to change the world coordinate frame of points and matrices. Default: [“X”, “Y”, “Z”]

Returns:

The attribute value.

static get_cam_attribute(cam_ob, attribute_name, local_frame_change=None, world_frame_change=None)[source]

Returns the value of the requested attribute for the given object.

Parameters:
  • cam_ob (Object) – The camera object.

  • attribute_name (str) – The attribute name.

  • local_frame_change (Optional[List[str]]) – Can be used to change the local coordinate frame of matrices. Default: [“X”, “Y”, “Z”]

  • world_frame_change (Optional[List[str]]) – Can be used to change the world coordinate frame of points and matrices. Default: [“X”, “Y”, “Z”]

Return type:

Any

Returns:

The attribute value.

static get_common_attribute(item, attribute_name, local_frame_change=None, world_frame_change=None)[source]

Returns the value of the requested attribute for the given item.

This method covers all general attributes that blender objects have.

Parameters:
  • item (Object) – The item. Type: blender object.

  • attribute_name (str) – The attribute name. Type: string.

  • local_frame_change (Optional[List[str]]) – Can be used to change the local coordinate frame of matrices. Default: [“X”, “Y”, “Z”]

  • world_frame_change (Optional[List[str]]) – Can be used to change the world coordinate frame of points and matrices. Default: [“X”, “Y”, “Z”]

Return type:

Any

Returns:

The attribute value.

static get_light_attribute(light, attribute_name, local_frame_change=None, world_frame_change=None)[source]

Returns the value of the requested attribute for the given light.

Parameters:
  • light (Light) – The light. Type: blender scene object of type light.

  • attribute_name (str) – The attribute name.

  • local_frame_change (Optional[List[str]]) – Can be used to change the local coordinate frame of matrices. Default: [“X”, “Y”, “Z”]

  • world_frame_change (Optional[List[str]]) – Can be used to change the world coordinate frame of points and matrices. Default: [“X”, “Y”, “Z”]

Return type:

Any

Returns:

The attribute value.

static get_stereo_path_pair(file_path)[source]

Returns stereoscopic file path pair for a given “normal” image file path.

Parameters:

file_path (str) – The file path of a single image.

Return type:

Tuple[str, str]

Returns:

The pair of file paths corresponding to the stereo images,

static load_csv(file_path)[source]

Load the csv file at the given path.

Parameters:

file_path (str) – The path. Type: string.

Return type:

List[Any]

Returns:

The content of the file

static load_output_file(file_path, load_alpha_channel=False, remove=True)[source]

Tries to read in the file with the given path into a numpy array.

Parameters:
  • file_path (str) – The file path. Type: string.

  • load_alpha_channel (bool) – Whether to load the alpha channel as well. Type: bool. Default: False

  • remove (bool) – Whether to delete file after loading.

Return type:

Union[ndarray, List[Any]]

Returns:

Loaded data from the file as numpy array if possible.

static load_registered_outputs(keys, keys_with_alpha_channel=None)[source]

Loads registered outputs with specified keys

Parameters:
  • keys (Set[str]) – set of output_key types to load

  • keys_with_alpha_channel (Optional[Set[str]]) – A set containing all keys whose alpha channels should be loaded.

Return type:

Dict[str, Union[ndarray, List[ndarray]]]

Returns:

dict of lists of raw loaded outputs. Keys are e.g. ‘distance’, ‘colors’, ‘normals’, ‘segmap’

static write_to_hdf_file(file, key, data, compression='gzip')[source]

Adds the given data as a new entry to the given hdf5 file.

Parameters:
  • file – The hdf5 file handle. Type: hdf5.File

  • key (str) – The key at which the data should be stored in the hdf5 file.

  • data (Union[ndarray, list, dict]) – The data to store.

blenderproc.python.writer.WriterUtility.write_hdf5(output_dir_path, output_data_dict, append_to_existing_output=False, stereo_separate_keys=False)[source]

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.