Skip to content

Commit

Permalink
Merge pull request #1338 from SamFlt/fix_dataset_generation_pose
Browse files Browse the repository at this point in the history
Dataset generation script: incorrect pose export (#1337)
  • Loading branch information
fspindle authored Feb 21, 2024
2 parents bab020d + a1f9e49 commit 9d1b517
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions script/dataset_generator/generate_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def convert_to_visp_frame(aTb):
Blender: +X = Right, +Y = Up, +Z = Behind
Same as converting to an OpenCV frame
'''
return bproc.math.change_source_coordinate_frame_of_transformation_matrix(aTb, ["X", "-Y", "-Z"])
aTbbis = aTb.copy()
aTbbis[1:3] = -aTbbis[1:3]
return aTbbis

def convert_points_to_visp_frame(points: np.ndarray):
'''
Expand Down Expand Up @@ -381,7 +383,6 @@ def save_data(self, path: Path, objects: List[bproc.types.MeshObject], data: Dic
hit_count += 1

final_visibility = base_visibility * (hit_count / len(ray_directions))
print(final_visibility)
# Including occlusions, the object is now not visible enough to be detectable
if final_visibility < min_visibility:
print(f'Filtered object {object.get_name()}, because of occlusions: {final_visibility}')
Expand Down Expand Up @@ -583,7 +584,7 @@ def create_target_objects(self) -> List[bproc.types.MeshObject]:
random_scale = np.random.uniform(-scale_noise, scale_noise) + 1.0
object.set_scale([random_scale, random_scale, random_scale]) # Uniform scaling
object.set_location([0.0, 0.0, 0.0])
object.persist_transformation_into_mesh()
object.persist_transformation_into_mesh(location=False, rotation=False, scale=True)

if displacement_amount > 0.0:
add_displacement(objects, displacement_amount)
Expand Down Expand Up @@ -659,7 +660,8 @@ def sample_pose(obj: bproc.types.MeshObject):
)

for object in objects:
object.persist_transformation_into_mesh()
object.persist_transformation_into_mesh(location=False, rotation=False, scale=True)


distractors = self.create_distractors(size)

Expand All @@ -670,8 +672,7 @@ def sample_pose(obj: bproc.types.MeshObject):
object.enable_rigidbody(False, collision_shape='BOX')

bproc.object.simulate_physics_and_fix_final_poses(min_simulation_time=3, max_simulation_time=3.5, check_object_interval=1)
for object in objects:
object.persist_transformation_into_mesh()

def filter_objects_outside_room(objects: List[bproc.types.MeshObject]) -> List[bproc.types.MeshObject]:
inside = []
outside = []
Expand All @@ -681,7 +682,7 @@ def filter_objects_outside_room(objects: List[bproc.types.MeshObject]) -> List[b
for object in outside:
object.delete()

print(f'Filtered {len(objects) - len(inside)} objects')
print(f'Filtered {len(objects) - len(inside)} objects that were outside the room')
return inside

objects = filter_objects_outside_room(objects)
Expand Down Expand Up @@ -787,5 +788,3 @@ def run(self):
bproc.init() # Works if you have a GPU

generator.run()


0 comments on commit 9d1b517

Please sign in to comment.