9 from pypointmatcher
import pointmatcher
as pm
10 from utils
import parse_translation, parse_rotation
20 is_transfo_saved =
False
27 config_file =
"../data/default.yaml"
32 output_base_directory =
"tests/icp/"
35 output_base_file =
"test"
42 init_translation =
"0,0,0" if is_3D
else "0,0"
45 init_rotation =
"1,0,0;0,1,0;0,0,1" if is_3D
else "1,0;0,1"
49 ref =
DP(DP.load(
'../data/car_cloud400.csv'))
50 data =
DP(DP.load(
'../data/car_cloud401.csv'))
54 ref =
DP(DP.load(
'../data/2D_twoBoxes.csv'))
55 data =
DP(DP.load(
'../data/2D_oneBox.csv'))
61 if len(config_file) == 0:
66 icp.loadFromYaml(config_file)
68 cloud_dimension = ref.getEuclideanDim()
70 assert cloud_dimension == 2
or cloud_dimension == 3,
"Invalid input point clouds dimension"
76 init_transfo = np.matmul(translation, rotation)
78 rigid_trans = PM.get().TransformationRegistrar.create(
"RigidTransformation")
80 if not rigid_trans.checkParameters(init_transfo):
81 print(
"Initial transformations is not rigid, identiy will be used")
82 init_transfo = np.identity(cloud_dimension + 1)
84 initialized_data = rigid_trans.compute(data, init_transfo)
87 T =
icp(initialized_data, ref)
90 print(f
"match ratio: {icp.errorMinimizer.getWeightedPointUsedRatio():.6}")
93 data_out =
DP(initialized_data)
94 icp.transformations.apply(data_out, T)
97 ref.save(f
"{output_base_directory + test_base}_{output_base_file}_ref.vtk")
98 data.save(f
"{output_base_directory + test_base}_{output_base_file}_data_in.vtk")
99 data_out.save(f
"{output_base_directory + test_base}_{output_base_file}_data_out.vtk")
102 init_file_name = f
"{output_base_directory + test_base}_{output_base_file}_init_transfo.txt"
103 icp_file_name = f
"{output_base_directory + test_base}_{output_base_file}_icp.transfo.txt"
104 complete_file_name = f
"{output_base_directory + test_base}_{output_base_file}_complete_transfo.txt"
106 with open(init_file_name,
"w")
as f:
107 f.write(f
"{init_transfo}".replace(
"[",
" ").replace(
"]",
" "))
109 with open(icp_file_name,
"w")
as f:
110 f.write(f
"{T}".replace(
"[",
" ").replace(
"]",
" "))
112 with open(complete_file_name,
"w")
as f:
113 f.write(f
"{np.matmul(T, init_transfo)}".replace(
"[",
" ").replace(
"]",
" "))
117 print(f
"{test_base} ICP transformation:\n{T}".replace(
"[",
" ").replace(
"]",
" "))