blenderproc.utility package

Module contents

class blenderproc.utility.BlockStopWatch(block_name)

Bases: object

Calls a print statement to mark the start and end of this block and also measures execution time.

Usage: with BlockStopWatch(‘text’):

class blenderproc.utility.LabelIdMapping

Bases: object

Handles category id mapping for semantic segmentation maps.

add(label, id_value)

Inserts the given label-id pair into the mapping.

Parameters:
  • label (str) – The label of the pair.

  • id_value (int) – The id of the pair

static from_csv(path, label_col_name='name', id_col_name='id')

Builds a label-id mapping based on the given csv file.

Parameters:
  • path – The path to a csv file.

  • label_col_name – The name of the column which should be used as label.

  • id_col_name – The name of the column which should be used as id.

Return type:

LabelIdMapping

Returns:

The built label mapping object.

static from_dict(label_to_id)

Builds a label-id mapping based on the given dict.

Parameters:

label_to_id (dict) – A dict where keys are labels and values are ids.

Return type:

LabelIdMapping

Returns:

The built label mapping object.

has_id(id_value)

Checks if the mapping contains the given id.

Parameters:

id_value (int) – The id to look for.

Return type:

bool

Returns:

True, if the id is already in use.

has_label(label)

Checks if the mapping contains the given label.

Parameters:

label (str) – The label to look for.

Return type:

bool

Returns:

True, if the label is already in use.

id_from_label(label)

Returns the id assigned to the given label.

Parameters:

label (str) – The label to look for.

Return type:

int

Returns:

The id with the given label.

label_from_id(id_value)

Returns the label assigned to the given id.

Parameters:

id_value (int) – The id to look for.

Return type:

str

Returns:

The label with the given id.

class blenderproc.utility.UndoAfterExecution(check_point_name=None, perform_undo_op=True)

Bases: object

Reverts all changes done to the blender project inside this block.

Usage: with UndoAfterExecution():

blenderproc.utility.generate_random_pattern_img(width, height, n_points)

Generate transparent image with random pattern.

Parameters:
  • width (int) – width of image to be generated.

  • height (int) – height of image to be generated.

  • n_points (int) – number of white points uniformly placed on image.

Return type:

ndarray

blenderproc.utility.num_frames()

Returns the currently total number of registered frames.

Return type:

int

Returns:

The number of frames.

blenderproc.utility.reset_keyframes()

Removes registered keyframes from all objects and resets frame_start and frame_end

Return type:

None

blenderproc.utility.resolve_path(path)

Returns an absolute path. If given path is relative, current working directory is put in front.

Parameters:

path (Union[str, Path]) – The path to resolve.

Return type:

str

Returns:

The absolute path.

blenderproc.utility.resolve_resource(relative_resource_path)

Returns an absolute path to the given BlenderProc resource.

Parameters:

relative_resource_path (str) – The relative path inside the BlenderProc resource folder.

Return type:

str

Returns:

The absolute path.

blenderproc.utility.set_keyframe_render_interval(frame_start=None, frame_end=None)

Sets frame_start and/or frame_end which determine the frames that will be rendered.

Parameters:
  • frame_start (Optional[int]) – The new frame_start value. If None, it will be ignored.

  • frame_end (Optional[int]) – The new frame_end value. If None, it will be ignored.