Skip to content

Commit e73868c

Browse files
committed
Fix issue with pose export: location and rotation were baked into mesh and thus camTworld was exported
1 parent bab020d commit e73868c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

script/dataset_generator/generate_scene.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def homogeneous_no_scaling(object: bproc.types.MeshObject, frame=None):
7676
localTworld = np.eye(4)
7777
localTworld[:3, :3] = object.get_rotation_mat(frame)
7878
localTworld[:3, 3] = object.get_location(frame)
79+
print('LOCAL T WORLD = ', localTworld)
7980
return localTworld
8081

8182
def convert_to_visp_frame(aTb):
@@ -84,7 +85,9 @@ def convert_to_visp_frame(aTb):
8485
Blender: +X = Right, +Y = Up, +Z = Behind
8586
Same as converting to an OpenCV frame
8687
'''
87-
return bproc.math.change_source_coordinate_frame_of_transformation_matrix(aTb, ["X", "-Y", "-Z"])
88+
aTbbis = aTb.copy()
89+
aTbbis[1:3] = -aTbbis[1:3]
90+
return aTbbis
8891

8992
def convert_points_to_visp_frame(points: np.ndarray):
9093
'''
@@ -339,6 +342,10 @@ def save_data(self, path: Path, objects: List[bproc.types.MeshObject], data: Dic
339342
if out_object_pose:
340343
worldTobj = homogeneous_no_scaling(object, frame)
341344
camTobj = camTworld @ worldTobj
345+
print('WorldTObject: ', worldTobj)
346+
print('camTObject: ', camTobj)
347+
print('camTworld: ', camTworld)
348+
342349
object_data['cTo'] = convert_to_visp_frame(camTobj)
343350
if out_bounding_box:
344351
bb_corners, z_front_proportion, points_im = bounding_box_2d_from_vertices(object, K, camTworld)
@@ -583,7 +590,7 @@ def create_target_objects(self) -> List[bproc.types.MeshObject]:
583590
random_scale = np.random.uniform(-scale_noise, scale_noise) + 1.0
584591
object.set_scale([random_scale, random_scale, random_scale]) # Uniform scaling
585592
object.set_location([0.0, 0.0, 0.0])
586-
object.persist_transformation_into_mesh()
593+
object.persist_transformation_into_mesh(location=False, rotation=False, scale=True)
587594

588595
if displacement_amount > 0.0:
589596
add_displacement(objects, displacement_amount)
@@ -659,7 +666,8 @@ def sample_pose(obj: bproc.types.MeshObject):
659666
)
660667

661668
for object in objects:
662-
object.persist_transformation_into_mesh()
669+
object.persist_transformation_into_mesh(location=False, rotation=False, scale=True)
670+
663671

664672
distractors = self.create_distractors(size)
665673

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

672680
bproc.object.simulate_physics_and_fix_final_poses(min_simulation_time=3, max_simulation_time=3.5, check_object_interval=1)
673-
for object in objects:
674-
object.persist_transformation_into_mesh()
681+
675682
def filter_objects_outside_room(objects: List[bproc.types.MeshObject]) -> List[bproc.types.MeshObject]:
676683
inside = []
677684
outside = []
@@ -787,5 +794,3 @@ def run(self):
787794
bproc.init() # Works if you have a GPU
788795

789796
generator.run()
790-
791-

0 commit comments

Comments
 (0)