fusion.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 
4 #include <pcl/io/pcd_io.h>
5 #include <pcl/io/ply_io.h>
6 #include <pcl/point_cloud.h>
7 #include <pcl/console/parse.h>
8 #include <pcl/common/transforms.h>
9 
10 // This is the main function
11 int
12 main (int argc, char** argv)
13 {
14 
15  pcl::PointCloud<pcl::PointXYZRGB> pos1, pos2, pos1_t;
16 
17 
18  pcl::io::loadPCDFile ("../data/pcd_pos1/pcd_2.pcd", pos1);
19  pcl::io::loadPCDFile ("../data/pcd_pos2/pcd_2.pcd", pos2);
20 
21  /* Reminder: how transformation matrices work :
22 
23  |-------> This column is the translation
24  | 1 0 0 x | \
25  | 0 1 0 y | }-> The identity 3x3 matrix (no rotation) on the left
26  | 0 0 1 z | /
27  | 0 0 0 1 | -> We do not use this line (and it has to stay 0,0,0,1)
28 
29  METHOD #1: Using a Matrix4f
30  This is the "manual" method, perfect to understand but error prone !
31  */
32 
33  Eigen::Matrix4d transform1 = Eigen::Matrix4d::Identity();
34  Eigen::Matrix4d transform2 = Eigen::Matrix4d::Identity();
35 
36  std::ifstream infile("../data/rts.txt");
37 
38  for(int i=0; i<4; i++)
39  {
40  for(int j=0; j<4; j++)
41  {
42  infile >> transform1(i,j);
43  }
44  }
45  for(int i=0; i<4; i++)
46  {
47  for(int j=0; j<4; j++)
48  {
49  infile >> transform2(i,j);
50  }
51  }
52  infile.close();
53  /*transform1 << 0.997577 , 0.0346118, 0.0603459, 0.805226,
54  -0.0319782, 0.998516, -0.0440743, -0.215247,
55  -0.0617819, 0.0420377, 0.997204, -0.111191,
56  0, 0, 0, 1;
57 
58 
59  transform2 << 0.998948, 0.0400165, 0.0223957, -0.525663,
60  -0.0399718, 0.999198, -0.00244055, -0.36611,
61  -0.0224754, 0.00154279, 0.999746, -0.0679732,
62  0, 0, 0 , 1;*/
63 
64  std::cout << transform1 << "\n" << transform2 <<"\n";
65 
66  Eigen::Matrix4d transform = transform2*(transform1.inverse());
67 
68  std::cout << "Final transform from camera1 to camera2 is:\n" << transform <<"\n";
69 
70 
71 
72 
73  pcl::transformPointCloud (pos1, pos1_t, transform);
74 
75  pos2 += pos1_t;
76  pcl::io::savePCDFileASCII ("../data/final_cloud.pcd", pos2);
77 
78 
79 
80 
81  return 0;
82 }
pcl::PointCloud< myPointXYZRID > transform(pcl::PointCloud< myPointXYZRID > pc, float x, float y, float z, float rot_x, float rot_y, float rot_z)
int main(int argc, char **argv)
Definition: fusion.cpp:12
int loadPCDFile(const std::string &file_name, sensor_msgs::PointCloud2 &cloud)


lidar_camera_calibration
Author(s):
autogenerated on Sat Feb 6 2021 03:39:37