0. 前言
笔者最近做在Ubuntu16.04下将点云bin文件转成pcd文件,借鉴的学习资料为小邋遢-lxh博主的两篇博客文章:
- 1.Ubuntu16.04下安装并测试pcl
- 2.Ubuntu16.04下将点云bin文件转成pcd文件
文章质量很好,自己最终也实现了最终效果,推荐大家学习!但是在做这个 实验的时候,也遇到了一个小问题,在此记录一下。
1. 遇到的问题
在做第一步没有遇到任何问题,最终也成功的测试了pcl安装是否成功!提示一下,刚开始大家可能看到的效果如下:
很多人误以为自己是不是做的不合适还是咋了,怎么和该博客主的最终效果不一致,其实大家做到这一步,pcl就已经安装正确并成功了,要显示和该博客主的一样效果,大家可以通过滑动鼠标滚轮,慢慢就会发现显示出原来博客主类似的运行效果了。
但是在做到第二篇文章的时候,按照博主的操作新建完所有文件夹的时候,在cmake编译完之后,执行make命令时给我报了一个错误,错误截图如下:
2. 错误分析以及解决办法
根据系统的提示,显示的是没有pcl/common/point_operators.h
这个头文件,我一直以为是自己PCL安装是不是不合适,没有安装好哪个包或者依赖啥的,又重新安装配置了一遍PCL,但是最终效果还是和之前一样。
后面我又开始查了一些其他关于PCL的程序,发现和其他博主并没有引这个头文件,于是将这个头文件删了,然后分别进行cmake ..
和make
操作,最终make成功了,make成功截图如下:
具体修改如下:
将该博主的bin2pcd.cpp替换为下面的程序:
#include <boost/program_options.hpp>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/common/io.h>
#include <pcl/search/organized.h>
#include <pcl/search/octree.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/surface/gp3.h>
#include <pcl/io/vtk_io.h>
#include <pcl/filters/voxel_grid.h>
#include <iostream>
#include <fstream>
using namespace pcl;
using namespace std;
namespace po = boost::program_options;
int main(int argc, char **argv){
///The file to read from.
string infile;
///The file to output to.
string outfile;
// Declare the supported options.
po::options_description desc("Program options");
desc.add_options()
//Options
("infile", po::value<string>(&infile)->required(), "the file to read a point cloud from")
("outfile", po::value<string>(&outfile)->required(), "the file to write the DoN point cloud & normals to")
;
// Parse the command line
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
// Print help
if (vm.count("help"))
{
cout << desc << "\n";
return false;
}
// Process options.
po::notify(vm);
// load point cloud
fstream input(infile.c_str(), ios::in | ios::binary);
if(!input.good()){
cerr << "Could not read file: " << infile << endl;
exit(EXIT_FAILURE);
}
input.seekg(0, ios::beg);
pcl::PointCloud<PointXYZI>::Ptr points (new pcl::PointCloud<PointXYZI>);
int i;
for (i=0; input.good() && !input.eof(); i++) {
PointXYZI point;
input.read((char *) &point.x, 3*sizeof(float));
input.read((char *) &point.intensity, sizeof(float));
points->push_back(point);
}
input.close();
cout << "Read KTTI point cloud with " << i << " points, writing to " << outfile << endl;
pcl::PCDWriter writer;
// Save DoN features
writer.write<PointXYZI> (outfile, *points, false);
}
其他操作继续按照该博主的操作进行即可!
3. 备注
最终我们成功把.bin文件转成了.pcd格式,
我的研究方向不是图像处理这一块,因为这是帮我研二的一个师兄做的一个小工作,但是我很好奇pcd格式文件到底是啥,我怎么看到这个效果,网上查了一些资料,发现利用命令pcl_viewer工具可以查看实际图像:
命令如下:
pcl_viewer XXX.pcd
//如果没有安装pcl_viewer,请实验 sudo apt-get install pcl_viewer安装此插件
最终显示效果如下: