Go to the documentation of this file.00001 #include "global_cloud_align.h"
00002
00003 using namespace rgbdtools;
00004
00005 int main(int argc, char** argv)
00006 {
00007 if (argc != 3)
00008 {
00009 printUsage(argv);
00010 return -1;
00011 }
00012
00013 std::string filename_in = argv[1];
00014 std::string filename_out = argv[2];
00015
00016
00017 printf("Reading cloud\n");
00018 PointCloudT::Ptr cloud;
00019 cloud.reset(new rgbdtools::PointCloudT());
00020 pcl::PCDReader reader;
00021 reader.read(filename_in, *cloud);
00022
00023 alignGlobalCloud(cloud);
00024
00025 return 0;
00026 }
00027
00028 void printUsage(char** argv)
00029 {
00030 std::cerr << "error: usage is " << argv[0]
00031 << " [filename_in] [filename_out]"
00032 << std::endl;
00033 }
00034
00035 void alignGlobalCloud(const PointCloudT::Ptr& cloud)
00036 {
00037 double vgf_res = 0.01;
00038
00039
00040 printf("Filtering cloud\n");
00041 PointCloudT::Ptr cloud_f;
00042 cloud_f.reset(new PointCloudT());
00043 pcl::VoxelGrid<PointT> vgf;
00044 vgf.setInputCloud(cloud);
00045 vgf.setLeafSize(vgf_res, vgf_res, vgf_res);
00046 vgf.filter(*cloud_f);
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 printf("Showing map\n");
00060 cv::Mat map_r;
00061 create2DProjectionImage(*cloud_f, map_r);
00062 cv::imshow("map_r", map_r);
00063 cv::waitKey(0);
00064
00065
00066 pcl::NormalEstimation<PointT, pcl::PointXYZRGBNormal> ne;
00067 ne.setInputCloud(cloud_f);
00068
00069
00070
00071 printf("Creating kd-tree\n");
00072 pcl::search::KdTree<PointT>::Ptr tree;
00073 tree.reset(new pcl::search::KdTree<PointT>());
00074 ne.setSearchMethod(tree);
00075
00076
00077 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr cloud_normals;
00078 cloud_normals.reset(new pcl::PointCloud<pcl::PointXYZRGBNormal>);
00079
00080
00081 ne.setRadiusSearch(0.05);
00082
00083
00084 printf("Estimating normals\n");
00085 ne.compute (*cloud_normals);
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 double hist_resolution = 0.25;
00107 cv::Mat hist_exp;
00108 buildExpectedPhiHistorgtam(hist_exp, hist_resolution, 5.0);
00109 cv::Mat hist_exp_img;
00110 createImageFromHistogram(hist_exp, hist_exp_img);
00111 cv::imshow("hist_exp_img", hist_exp_img);
00112
00113
00114 printf("creating histogram\n");
00115 cv::Mat hist;
00116 buildPhiHistogram(*cloud_normals, hist, hist_resolution);
00117
00118
00119 printf("showing histogram\n");
00120 cv::Mat hist_img;
00121 createImageFromHistogram(hist, hist_img);
00122 cv::imshow("Histogram Phi", hist_img);
00123 cv::waitKey(0);
00124
00125
00126 double best_angle;
00127 alignHistogram(hist, hist_exp, hist_resolution, best_angle);
00128 printf("best_angle: %f\n", best_angle);
00129
00130
00131 cv::Mat hist_best;
00132 shiftHistogram(hist, hist_best, best_angle/hist_resolution);
00133 cv::Mat hist_best_img;
00134 createImageFromHistogram(hist_best, hist_best_img);
00135 cv::imshow("hist_best_img", hist_best_img);
00136 cv::waitKey(0);
00137
00138
00139 AffineTransform best_tf;
00140 XYZRPYToEigenAffine(0, 0, 0, 0, 0, best_angle * M_PI/180.0, best_tf);
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 pcl::transformPointCloud(*cloud_f, *cloud_f, best_tf);
00152
00153
00154 cv::Mat map_f;
00155 create2DProjectionImage(*cloud_f, map_f);
00156 cv::imshow("map_f", map_f);
00157 cv::waitKey(0);
00158
00159 printf("Done\n");
00160 }