1+ #include " open3d/geometry/PointCloud.h"
2+ #include " open3d/io/PointCloudIO.h"
3+ #include < open3d/pipelines/registration/Registration.h>
4+ #include < open3d/visualization/visualizer/Visualizer.h>
5+ #include < yaml-cpp/yaml.h>
6+ #include < kitti_tools.h>
7+ #include < tuple>
8+ #include < iostream>
9+ #include < Eigen/Dense>
10+ int main (int argc, char ** argv)
11+ {
12+ if (argc < 2 ){
13+ std::cerr << " Need config_file arg" << std::endl;
14+ exit (0 );
15+ }
16+ YAML::Node config = YAML::LoadFile (argv[1 ]);
17+ YAML::Node io_config = config[" io" ];
18+ YAML::Node runtime_config = config[" runtime" ];
19+ YAML::Node vis_config = config[" vis" ];
20+ const std::string lidar_pcd_filename = io_config[" lidar_pcd" ].as <std::string>();
21+ const std::string cam_pcd_filename = io_config[" cam_pcd" ].as <std::string>();
22+ const std::string init_sim3_filename = io_config[" init_sim3" ].as <std::string>();
23+ const std::string FrameIdFile = io_config[" FrameId" ].as <std::string>();
24+ const std::string savePath = io_config[" savePath" ].as <std::string>();
25+
26+ const double icp_corr_dist = runtime_config[" max_corr_dist" ].as <double >();
27+ const int icp_max_iter = runtime_config[" max_iter" ].as <int >();
28+
29+ const bool use_vis = vis_config[" use_vis" ].as <bool >();
30+ const std::string vis_name = vis_config[" name" ].as <std::string>();
31+ const int height = vis_config[" height" ].as <int >();
32+ const int width = vis_config[" width" ].as <int >();
33+ const std::vector<float > cam_color = vis_config[" cam_pcd_color" ].as <std::vector<float > >();
34+ const std::vector<float > lidar_color = vis_config[" lidar_pcd_color" ].as <std::vector<float > >();
35+
36+ YAML::Node FrameIdConfig = YAML::LoadFile (FrameIdFile);
37+ std::vector<int > FrameId = FrameIdConfig[" mnFrameId" ].as <std::vector<int > >();
38+ std::shared_ptr<open3d::geometry::PointCloud> LidarPtPtr (new open3d::geometry::PointCloud ());
39+ std::shared_ptr<open3d::geometry::PointCloud> CamPtPtr (new open3d::geometry::PointCloud ());
40+ open3d::io::ReadPointCloudOption option (" auto" , true , true , true );
41+ open3d::io::ReadPointCloud (lidar_pcd_filename, *LidarPtPtr, option);
42+ open3d::io::ReadPointCloud (cam_pcd_filename, *CamPtPtr, option);
43+ if (FrameId[0 ] != 0 )
44+ {
45+ std::cout << " Camera Reference Frame: " << FrameId[0 ] << " (!=0), need transform to the reference" << std::endl;
46+ const std::string lidar_posefile = io_config[" lidar_pose" ].as <std::string>();
47+ std::vector<Eigen::Isometry3d> lidar_poses;
48+ ReadPoseList (lidar_posefile, lidar_poses);
49+ Eigen::Isometry3d refpose = lidar_poses[FrameId[0 ]];
50+ LidarPtPtr->Transform (refpose.inverse ().matrix ());
51+ }
52+ Eigen::Matrix4d init_sim3;
53+ double init_scale;
54+ std::tie (init_sim3, init_scale) = readSim3 (init_sim3_filename);
55+ init_sim3.topLeftCorner (3 ,3 ) = init_sim3.topLeftCorner (3 ,3 ).transpose ().eval (); // R^T
56+ init_sim3.topRightCorner (3 ,1 ) = -init_sim3.topLeftCorner (3 ,3 ) * init_sim3.topRightCorner (3 ,1 ); // -R^T * t
57+ std::cout << " Raw RCL:\n " << init_sim3.topLeftCorner (3 ,3 ) << std::endl;
58+ std::cout << " Raw tCL:\n " << init_sim3.topRightCorner (3 ,1 ).transpose ().eval () << std::endl;
59+ std::cout << " Raw scale:" << init_scale << std::endl;
60+ init_sim3.topLeftCorner (3 ,3 ) *= init_scale;
61+ open3d::pipelines::registration::ICPConvergenceCriteria criteria;
62+ criteria.max_iteration_ = icp_max_iter;
63+ auto reg = open3d::pipelines::registration::RegistrationICP (
64+ *CamPtPtr, *LidarPtPtr, icp_corr_dist, init_sim3,
65+ open3d::pipelines::registration::TransformationEstimationPointToPoint (true ),criteria
66+ );
67+ Eigen::Matrix3d diag = reg.transformation_ .topLeftCorner (3 ,3 ) * reg.transformation_ .topLeftCorner (3 ,3 ).transpose ();
68+ double scale = sqrt (diag (0 ,0 ));
69+ Eigen::Matrix4d se3 (reg.transformation_ );
70+ se3.topLeftCorner (3 ,3 ) /= scale;
71+ se3 = se3.inverse ().eval ();
72+ std::cout << " Tuned RCL:\n " << se3.topLeftCorner (3 ,3 ) << std::endl;
73+ std::cout << " Tuned tCL:\n " << se3.topRightCorner (3 ,1 ).transpose () << std::endl;
74+ std::cout << " Tuned scale:\n " << scale << std::endl;
75+ CamPtPtr->Transform (reg.transformation_ );
76+ CamPtPtr->PaintUniformColor ((Eigen::Vector3d () << cam_color[0 ], cam_color[1 ], cam_color[2 ]).finished ());
77+ LidarPtPtr->PaintUniformColor ((Eigen::Vector3d () << lidar_color[0 ], lidar_color[1 ], lidar_color[2 ]).finished ());
78+ if (use_vis){
79+ open3d::visualization::Visualizer visualizer;
80+ visualizer.CreateVisualizerWindow (vis_name, width, height);
81+ visualizer.AddGeometry (CamPtPtr);
82+ visualizer.AddGeometry (LidarPtPtr);
83+ visualizer.Run ();
84+ }
85+ writeSim3 (savePath, se3, scale);
86+ }
0 commit comments