PointCloud踩坑上手C++

本文介绍 PointCloud踩坑上手C++

PointCloud踩坑上手C++

This article was original written by Jin Tian, welcome re-post, first come with https://jinfagang.github.io . but please keep this copyright info, thanks, any question could be asked via wechat: jintianiloveu

pcl 问题还是蛮多的,为了快速的写一些测试案例,不得不探索一下如何用Makefile链接它。现在有了一个Makefile模板:

CC = g++
CFLAGS = -g -Wall
SRCS = r.cpp
PROG = example
# based on usage, libaries can be add or remove
OPENCV = `pkg-config opencv --cflags --libs`
THOR = -lthor
PCL = -lpcl_io -lpcl_visualization -lpcl_common -lpcl_features
VTK = -I/usr/local/include/vtk -lvtkCommonCore-8.1
BOOST = -lboost_regex -lboost_system
LIBS = $(OPENCV) $(THOR) $(PCL) $(VTK) $(BOOST)
$(PROG):$(SRCS)
$(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)

这个用来编译我们的小小的pcl测试程序:

#include "opencv/cv.hpp"
#include <opencv2/core/types.hpp>
#include <opencv/cv.hpp>
#include "thor/os.h"
#include <iostream>
#include "pcl/common/common_headers.h"
#include "pcl/io/pcd_io.h"
#include "pcl/visualization/pcl_visualizer.h"
#include "pcl/visualization/cloud_viewer.h"
using namespace std;
using namespace cv;
void showBasicCloud()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr basic_cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>());
// create a circle cloud
for (float z = -1.0; z <= 1.0; z += 0.05)
{
for (float angle = 0.0; angle <= 360.0; angle += 5)
{
pcl::PointXYZ basic_point;
basic_point.x = 0.5 * cosf(pcl::deg2rad(angle));
basic_point.y = sinf(pcl::deg2rad(angle));
basic_point.z = z;
cout << basic_point << endl;
basic_cloud_ptr->points.push_back(basic_point);
}
}
cout << basic_cloud_ptr->points.size() << endl;
pcl::PointCloud<pcl::PointXYZ> &cloud = *basic_cloud_ptr; //点云
cloud.points.resize(1*cloud.points.size());
cout << "cloud shape: " << cloud.width << "x" << cloud.height << endl;
pcl::io::savePCDFileASCII("test_pcd.pcd", cloud);
cout << "Saved " << basic_cloud_ptr->points.size() << " data points to test_pcd.pcd." << std::endl;
// how this cloud
pcl::visualization::CloudViewer viewer("simple cloud viewer");
// viwer.setBackgroundColor()
viewer.showCloud(basic_cloud_ptr);
while (!viewer.wasStopped())
{
}
}
int main()
{
showBasicCloud();
return 1;
}

这个程序其实很简单,就是新建一个测试的案例,然后添加一下点到点云中,最后显示出来,但是最后却core dumped了,什么原因???

总的来说问题比较复杂。