for i in range(15): interior_objects.extend( IKEALoader.load(args.ikea_path, ["bed", "chair", "desk", "bookshelf"])) # Construct random room and fill with interior_objects objects = RandomRoomConstructor.construct(25, interior_objects, materials, amount_of_extrusions=5) # Bring light into the room SurfaceLighting.run([obj for obj in objects if obj.get_name() == "Ceiling"], emission_strength=4.0) # Init bvh tree containing all mesh objects bvh_tree = MeshObject.create_bvh_tree_multi_objects(objects) floor = [obj for obj in objects if obj.get_name() == "Floor"][0] poses = 0 tries = 0 while tries < 10000 and poses < 5: # Sample point location = UpperRegionSampler.sample(floor, min_height=1.5, max_height=1.8) # Sample rotation rotation = np.random.uniform([1.0, 0, 0], [1.4217, 0, 6.283185307]) cam2world_matrix = MathUtility.build_transformation_mat(location, rotation) # Check that obstacles are at least 1 meter away from the camera and make sure the view interesting enough if CameraValidation.perform_obstacle_in_view_check(cam2world_matrix, {"min": 1.2}, bvh_tree) and \ CameraValidation.scene_coverage_score(cam2world_matrix) > 0.4 and \ floor.position_is_above_object(location): # Persist camera pose
Initializer.init() # load the objects into the scene label_mapping = LabelIdMapping.from_csv( Utility.resolve_path( os.path.join('resources', 'id_mappings', 'nyu_idset.csv'))) objs = SuncgLoader.load(args.house, label_mapping) # makes Suncg objects emit light SuncgLighting.light() # Init sampler for sampling locations inside the loaded suncg house point_sampler = SuncgPointInRoomSampler(objs) # Init bvh tree containing all mesh objects bvh_tree = MeshObject.create_bvh_tree_multi_objects( [o for o in objs if isinstance(o, MeshObject)]) poses = 0 tries = 0 while tries < 10000 and poses < 5: # Sample point inside house height = np.random.uniform(0.5, 2) location, _ = point_sampler.sample(height) # Sample rotation (fix around X and Y axis) euler_rotation = np.random.uniform([1.2217, 0, 0], [1.2217, 0, 6.283185307]) cam2world_matrix = MathUtility.build_transformation_mat( location, euler_rotation) # Check that obstacles are at least 1 meter away from the camera and make sure the view interesting enough if CameraValidation.perform_obstacle_in_view_check(
def _sample_cam_poses(self, config): """ Samples camera poses according to the given config :param config: The config object """ cam_ob = bpy.context.scene.camera cam = cam_ob.data # Set global parameters self.sqrt_number_of_rays = config.get_int("sqrt_number_of_rays", 10) self.max_tries = config.get_int("max_tries", 10000) self.proximity_checks = config.get_raw_dict("proximity_checks", {}) self.excluded_objects_in_proximity_check = config.get_list( "excluded_objs_in_proximity_check", []) self.min_interest_score = config.get_float("min_interest_score", 0.0) self.interest_score_range = config.get_float("interest_score_range", self.min_interest_score) self.interest_score_step = config.get_float("interest_score_step", 0.1) self.special_objects = config.get_list("special_objects", []) self.special_objects_weight = config.get_float( "special_objects_weight", 2) self._above_objects = MeshObject.convert_to_meshes( config.get_list("check_if_pose_above_object_list", [])) self.check_visible_objects = MeshObject.convert_to_meshes( config.get_list("check_if_objects_visible", [])) # Set camera intrinsics self._set_cam_intrinsics( cam, Config(self.config.get_raw_dict("intrinsics", {}))) if self.proximity_checks: # needs to build an bvh tree mesh_objects = [ MeshObject(obj) for obj in get_all_blender_mesh_objects() if obj not in self.excluded_objects_in_proximity_check ] self.bvh_tree = MeshObject.create_bvh_tree_multi_objects( mesh_objects) if self.interest_score_step <= 0.0: raise Exception( "Must have an interest score step size bigger than 0") # Determine the number of camera poses to sample number_of_poses = config.get_int("number_of_samples", 1) print("Sampling " + str(number_of_poses) + " cam poses") # Start with max interest score self.interest_score = self.interest_score_range # Init all_tries = 0 tries = 0 existing_poses = [] for i in range(number_of_poses): # Do until a valid pose has been found or the max number of tries has been reached while tries < self.max_tries: tries += 1 all_tries += 1 # Sample a new cam pose and check if its valid if self.sample_and_validate_cam_pose(config, existing_poses): break # If max tries has been reached if tries >= self.max_tries: # Decrease interest score and try again, if we have not yet reached minimum continue_trying, self.interest_score = CameraValidation.decrease_interest_score( self.interest_score, self.min_interest_score, self.interest_score_step) if continue_trying: tries = 0 print(str(all_tries) + " tries were necessary")