Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <pcl/console/parse.h>
00041 #include <pcl/io/pcd_io.h>
00042 #include <pcl/point_types.h>
00043 #include <pcl/registration/icp.h>
00044 #include <pcl/registration/icp_nl.h>
00045 #include <pcl/registration/transformation_estimation_lm.h>
00046 #include <pcl/registration/warp_point_rigid_3d.h>
00047
00048 #include <string>
00049 #include <iostream>
00050 #include <fstream>
00051 #include <vector>
00052
00053 typedef pcl::PointXYZ PointType;
00054 typedef pcl::PointCloud<PointType> Cloud;
00055 typedef Cloud::ConstPtr CloudConstPtr;
00056 typedef Cloud::Ptr CloudPtr;
00057
00058 int
00059 main (int argc, char **argv)
00060 {
00061 double dist = 0.05;
00062 pcl::console::parse_argument (argc, argv, "-d", dist);
00063
00064 double rans = 0.05;
00065 pcl::console::parse_argument (argc, argv, "-r", rans);
00066
00067 int iter = 50;
00068 pcl::console::parse_argument (argc, argv, "-i", iter);
00069
00070 std::vector<int> pcd_indices;
00071 pcd_indices = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");
00072
00073 CloudPtr model (new Cloud);
00074 if (pcl::io::loadPCDFile (argv[pcd_indices[0]], *model) == -1)
00075 {
00076 std::cout << "Could not read file" << std::endl;
00077 return -1;
00078 }
00079 std::cout << argv[pcd_indices[0]] << " width: " << model->width << " height: " << model->height << std::endl;
00080
00081 std::string result_filename (argv[pcd_indices[0]]);
00082 result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
00083 pcl::io::savePCDFile (result_filename.c_str (), *model);
00084 std::cout << "saving first model to " << result_filename << std::endl;
00085
00086 Eigen::Matrix4f t (Eigen::Matrix4f::Identity ());
00087
00088 for (size_t i = 1; i < pcd_indices.size (); i++)
00089 {
00090 CloudPtr data (new Cloud);
00091 if (pcl::io::loadPCDFile (argv[pcd_indices[i]], *data) == -1)
00092 {
00093 std::cout << "Could not read file" << std::endl;
00094 return -1;
00095 }
00096 std::cout << argv[pcd_indices[i]] << " width: " << data->width << " height: " << data->height << std::endl;
00097
00098 pcl::IterativeClosestPointNonLinear<PointType, PointType> icp;
00099
00100 boost::shared_ptr<pcl::WarpPointRigid3D<PointType, PointType> > warp_fcn
00101 (new pcl::WarpPointRigid3D<PointType, PointType>);
00102
00103
00104 boost::shared_ptr<pcl::registration::TransformationEstimationLM<PointType, PointType> > te (new pcl::registration::TransformationEstimationLM<PointType, PointType>);
00105 te->setWarpFunction (warp_fcn);
00106
00107
00108 icp.setTransformationEstimation (te);
00109
00110 icp.setMaximumIterations (iter);
00111 icp.setMaxCorrespondenceDistance (dist);
00112 icp.setRANSACOutlierRejectionThreshold (rans);
00113
00114 icp.setInputTarget (model);
00115
00116 icp.setInputCloud (data);
00117
00118 CloudPtr tmp (new Cloud);
00119 icp.align (*tmp);
00120
00121 t = icp.getFinalTransformation () * t;
00122
00123 pcl::transformPointCloud (*data, *tmp, t);
00124
00125 std::cout << icp.getFinalTransformation () << std::endl;
00126
00127 *model = *data;
00128
00129 std::string result_filename (argv[pcd_indices[i]]);
00130 result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
00131 pcl::io::savePCDFileBinary (result_filename.c_str (), *tmp);
00132 std::cout << "saving result to " << result_filename << std::endl;
00133 }
00134
00135 return 0;
00136 }