blenderproc.python.modules.camera.CameraSampler module

class blenderproc.python.modules.camera.CameraSampler.CameraSampler(config)[source]

Bases: blenderproc.python.modules.camera.CameraInterface.CameraInterface

A general camera sampler.

First a camera pose is sampled according to the configuration, then it is checked if the pose is valid. If that’s not the case a new camera pose is sampled instead.

Supported cam pose validation methods: - Checking if the distance to objects is in a configured range - Checking if the scene coverage/interestingness score is above a configured threshold - Checking if a candidate pose is sufficiently different than the sampled poses so far

Example 1: Sampling 10 camera poses.

{
  "module": "camera.SuncgCameraSampler",
  "config": {
    "cam_poses": [
    {
      "number_of_samples": 10,
      "proximity_checks": {
        "min": 1.0
      },
      "min_interest_score": 0.4,
      "location": {
        "provider":"sampler.Uniform3d",
        "max":[0, 0, 2],
        "min":[0, 0, 0.5]
      },
      "rotation": {
        "value": {
          "provider":"sampler.Uniform3d",
          "max":[1.2217, 0, 6.283185307],
          "min":[1.2217, 0, 0]
        }
      }
    }
    ]
  }
}

Configuration:

Parameter Description Type
intrinsics A dict which contains the intrinsic camera parameters. Check CameraInterface for more info. Default: {}. dict
cam_poses Camera poses configuration list. Each cell contains a separate config data. list
default_cam_param A dict which can be used to specify properties across all cam poses. Check CameraInterface for more info. Default: {}. dict

Properties per cam pose:

Parameter Description Type
number_of_samples The number of camera poses that should be sampled. Note depending on some constraints (e.g. interest scores), the sampler might not return all of the camera poses if the number of tries exceeded the configured limit. Default: 1. int
max_tries The maximum number of tries that should be made to sample the requested number of cam poses per interest score. Default: 10000. int
sqrt_number_of_rays The square root of the number of rays which will be used to determine, if there is an obstacle in front of the camera. Default: 10. int
proximity_checks A dictionary containing operators (e.g. avg, min) as keys and as values dictionaries containing thresholds in the form of {“min”: 1.0, “max”:4.0} or just the numerical threshold in case of max or min. The operators are combined in conjunction (i.e boolean AND). This can also be used to avoid the background in images, with the no_background: True option. Default: {}. dict
excluded_objs_in_proximity_check A list of objects, returned by getter.Entity to remove some objects from the proximity checks defined in ‘proximity_checks’. Default: [] list
min_interest_score Arbitrary threshold to discard cam poses with less interesting views. Default: 0.0. float
interest_score_range The maximum of the range of interest scores that would be used to sample the camera poses. Interest score range example: min_interest_score = 0.8, interest_score_range = 1.0, interest_score_step = 0.1 interest score list = [1.0, 0.9, 0.8]. The sampler would reject any pose with score less than 1.0. If max tries is reached, it would switch to 0.9 and so on. min_interest_score = 0.8, interest_score_range = 0.8, interest_score_step = 0.1 (or any value bigger than 0) interest score list = [0.8]. Default: min_interest_score. float
interest_score_step Step size for the list of interest scores that would be tried in the range from min_interest_score to interest_score_range. Must be bigger than 0. ” Default: 0.1. float
special_objects Objects that weights differently in calculating whether the scene is interesting or not, uses the coarse_grained_class or if not SUNCG, 3D Front, the category_id. Default: []. list
special_objects_weight Weighting factor for more special objects, used to estimate the interestingness of the scene. Default: 2.0. float
check_pose_novelty_rot Checks that a sampled new pose is novel with respect to the rotation component. Default: False bool
check_pose_novelty_translation Checks that a sampled new pose is novel with respect to the translation component. Default: False. bool
min_var_diff_rot Considers a pose novel if it increases the variance of the rotation component of all poses sampled by this parameter’s value in percentage. If set to -1, then it would only check that the variance is increased. Default: sys.float_info.min. float
min_var_diff_translation Same as min_var_diff_rot but for translation. If set to -1, then it would only check that the variance is increased. Default: sys.float_info.min. float
check_if_pose_above_object_list A list of objects, where each camera has to be above, could be the floor or a table. Default: []. list
check_if_objects_visible A list of objects, which always should be visible in the camera view. Default: []. list
_is_pose_valid(cam2world_matrix, existing_poses)[source]

Determines if the given pose is valid.

  • Checks if the distance to objects is in the configured range
  • Checks if the scene coverage score is above the configured threshold
Parameters:
  • cam2world_matrix (ndarray) – The sampled camera extrinsics in form of a camera to world frame transformation matrix.
  • existing_poses (List[ndarray]) – The list of already sampled valid poses.
Return type:

bool

Returns:

True, if the pose is valid

_on_new_pose_added(cam2world_matrix, frame)[source]
Parameters:
  • cam2world_matrix (ndarray) – The new camera pose.
  • frame (int) – The frame containing the new pose.
_sample_cam_poses(config)[source]

Samples camera poses according to the given config

Parameters:config – The config object
_sample_pose(config)[source]
Return type:ndarray
Returns:The new sampled pose.
run()[source]

Sets camera poses.

sample_and_validate_cam_pose(config, existing_poses)[source]

Samples a new camera pose, sets the parameters of the given camera object accordingly and validates it.

Parameters:
  • config (Config) – The config object describing how to sample
  • existing_poses (List[ndarray]) – A list of already sampled valid poses.
Return type:

bool

Returns:

True, if the sampled pose was valid