Skip to content

Commit

Permalink
Fix issue with pose export: location and rotation were baked into mes…
Browse files Browse the repository at this point in the history
…h and thus camTworld was exported
  • Loading branch information
SamFlt committed Feb 20, 2024
1 parent bab020d commit e73868c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions script/dataset_generator/generate_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def homogeneous_no_scaling(object: bproc.types.MeshObject, frame=None):
localTworld = np.eye(4)
localTworld[:3, :3] = object.get_rotation_mat(frame)
localTworld[:3, 3] = object.get_location(frame)
print('LOCAL T WORLD = ', localTworld)
return localTworld

def convert_to_visp_frame(aTb):
Expand All @@ -84,7 +85,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 @@ -339,6 +342,10 @@ def save_data(self, path: Path, objects: List[bproc.types.MeshObject], data: Dic
if out_object_pose:
worldTobj = homogeneous_no_scaling(object, frame)
camTobj = camTworld @ worldTobj
print('WorldTObject: ', worldTobj)
print('camTObject: ', camTobj)
print('camTworld: ', camTworld)

object_data['cTo'] = convert_to_visp_frame(camTobj)
if out_bounding_box:
bb_corners, z_front_proportion, points_im = bounding_box_2d_from_vertices(object, K, camTworld)
Expand Down Expand Up @@ -583,7 +590,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 +666,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 +678,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 Down Expand Up @@ -787,5 +794,3 @@ def run(self):
bproc.init() # Works if you have a GPU

generator.run()


0 comments on commit e73868c

Please sign in to comment.