debug view sample
This commit is contained in:
@@ -133,25 +133,58 @@ class CADStrategyRunner(Runner):
|
||||
Log.info(f"[{count_object}/{total}]Processing {model_name}")
|
||||
self.run_one_model(model_name)
|
||||
Log.success(f"[{count_object}/{total}]Finished processing {model_name}")
|
||||
|
||||
|
||||
|
||||
# ---------------------------- test ---------------------------- #
|
||||
if __name__ == "__main__":
|
||||
|
||||
model_path = r"C:\Users\hofee\Downloads\mesh.obj"
|
||||
model = trimesh.load(model_path)
|
||||
test_pts_L = np.load(r"C:\Users\hofee\Downloads\0.npy")
|
||||
|
||||
import open3d as o3d
|
||||
def add_noise(points, translation, rotation):
|
||||
R = o3d.geometry.get_rotation_matrix_from_axis_angle(rotation)
|
||||
noisy_points = points @ R.T + translation
|
||||
return noisy_points
|
||||
''' test register '''
|
||||
# test_pts_L = np.load(r"C:\Users\hofee\Downloads\0.npy")
|
||||
|
||||
translation_noise = np.random.uniform(-0.5, 0.5, size=3)
|
||||
rotation_noise = np.random.uniform(-np.pi/4, np.pi/4, size=3)
|
||||
noisy_pts_L = add_noise(test_pts_L, translation_noise, rotation_noise)
|
||||
# import open3d as o3d
|
||||
# def add_noise(points, translation, rotation):
|
||||
# R = o3d.geometry.get_rotation_matrix_from_axis_angle(rotation)
|
||||
# noisy_points = points @ R.T + translation
|
||||
# return noisy_points
|
||||
|
||||
cad_to_cam_L = PtsUtil.register(noisy_pts_L, model)
|
||||
# translation_noise = np.random.uniform(-0.5, 0.5, size=3)
|
||||
# rotation_noise = np.random.uniform(-np.pi/4, np.pi/4, size=3)
|
||||
# noisy_pts_L = add_noise(test_pts_L, translation_noise, rotation_noise)
|
||||
|
||||
cad_pts_L = PtsUtil.transform_point_cloud(noisy_pts_L, cad_to_cam_L)
|
||||
np.savetxt(r"test.txt", cad_pts_L)
|
||||
np.savetxt(r"src.txt", noisy_pts_L)
|
||||
# cad_to_cam_L = PtsUtil.register(noisy_pts_L, model)
|
||||
|
||||
# cad_pts_L = PtsUtil.transform_point_cloud(noisy_pts_L, cad_to_cam_L)
|
||||
# np.savetxt(r"test.txt", cad_pts_L)
|
||||
# np.savetxt(r"src.txt", noisy_pts_L)
|
||||
|
||||
''' test view sample '''
|
||||
|
||||
sampled_view_data = ViewSampleUtil.sample_view_data_world_space(
|
||||
model, np.eye(4),
|
||||
voxel_size = 0.005,
|
||||
max_views = 20,
|
||||
min_cam_table_included_degree= 20,
|
||||
random_view_ratio = 0
|
||||
)
|
||||
cam_poses = sampled_view_data["cam_to_world_poses"]
|
||||
cam_poses = np.array(cam_poses)
|
||||
print(cam_poses.shape)
|
||||
def sample_camera_direction(cam_pose, num_samples, sample_distance):
|
||||
cam_position = cam_pose[:3, 3]
|
||||
cam_direction = cam_pose[:3, 2]
|
||||
sampled_points = np.array([cam_position - (i + 1) * sample_distance * cam_direction for i in range(num_samples)])
|
||||
return sampled_points
|
||||
|
||||
all_sampled_points = []
|
||||
for i in range(cam_poses.shape[0]):
|
||||
samped_points = sample_camera_direction(cam_poses[i], 10, 0.02)
|
||||
all_sampled_points.append(samped_points)
|
||||
|
||||
all_sampled_points = np.concatenate(all_sampled_points, axis=0)
|
||||
np.savetxt(r"cam_poses.txt", cam_poses[:, :3, 3])
|
||||
np.savetxt(r"cam_directions.txt", all_sampled_points)
|
||||
|
||||
|
Reference in New Issue
Block a user