icp_simple.py
Go to the documentation of this file.
1 # Code example for ICP taking 2 points clouds (2D or 3D) relatively close
2 # and computing the transformation between them.
3 
4 from pypointmatcher import pointmatcher as pm
5 
6 PM = pm.PointMatcher
7 DP = PM.DataPoints
8 
9 # Path of output directory (default: tests/icp_simple/)
10 # The output directory must already exist
11 # Leave empty to save in the current directory
12 output_base_directory = "tests/icp_simple/"
13 
14 # Name of output files (default: test)
15 output_base_file = "test"
16 
17 # Toggle to switch between 2D and 3D clouds
18 is_3D = True
19 
20 if is_3D:
21  # Load 3D point clouds
22  ref = DP(DP.load('../data/car_cloud400.csv'))
23  data = DP(DP.load('../data/car_cloud401.csv'))
24  test_base = "3D"
25 else:
26  # Load 2D point clouds
27  ref = DP(DP.load('../data/2D_twoBoxes.csv'))
28  data = DP(DP.load('../data/2D_oneBox.csv'))
29  test_base = "2D"
30 
31 # Create the default ICP algorithm
32 icp = PM.ICP()
33 
34 # See the implementation of setDefault() to create a custom ICP algorithm
35 icp.setDefault()
36 
37 # Compute the transformation to express data in ref
38 T = icp(data, ref)
39 
40 # Transform data to express it in ref
41 data_out = DP(data)
42 icp.transformations.apply(data_out, T)
43 
44 # Save files to see the results
45 ref.save(f"{output_base_directory + test_base}_{output_base_file}_ref.vtk")
46 data.save(f"{output_base_directory + test_base}_{output_base_file}_data_in.vtk")
47 data_out.save(f"{output_base_directory + test_base}_{output_base_file}_data_out.vtk")
48 
49 print(f"Final {test_base} transformations:\n{T}\n".replace("[", " ").replace("]", " "))
Definition: icp.py:1


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:02