Ubuntu16.04安装编译pcl点云库
在ubuntu下安装pcl点云库时,网上给出的教程,大多是分了几个步骤,安装pcl和其依赖库,未免过于麻烦,其实有很简单的方法,一行就可以搞定。
sudo apt-get install libpcl-dev
这样,对应的依赖项和pcl库都被安装编译好了,然后使用pcl_viewer测试下吧!
where options are:-bc r,g,b = background color-fc r,g,b = foreground color-ps X = point size (1..64) -opaque X = rendered point cloud opacity (0..1)-shading X = rendered surface shading ('flat' (default), 'gouraud', 'phong')-position x,y,z = absolute point cloud position in metres-orientation r,p,y = absolute point cloud orientation (roll, pitch, yaw) in radians-ax n = enable on-screen display of XYZ axes and scale them to n-ax_pos X,Y,Z = if axes are enabled, set their X,Y,Z position in space (default 0,0,0)-cam (*) = use given camera settings as initial view(*) [Clipping Range / Focal Point / Position / ViewUp / Distance / Field of View Y / Window Size / Window Pos] or use a <filename.cam> that contains the same information.-multiview 0/1 = enable/disable auto-multi viewport rendering (default disabled)-normals 0/X = disable/enable the display of every Xth point's surface normal as lines (default disabled)-normals_scale X = resize the normal unit vector size to X (default 0.02)-pc 0/X = disable/enable the display of every Xth point's principal curvatures as lines (default disabled)-pc_scale X = resize the principal curvatures vectors size to X (default 0.02)-immediate_rendering 0/1 = use immediate mode rendering to draw the data (default: disabled)Note: the use of immediate rendering will enable the visualization of larger datasets at the expense of extra RAM.See http://en.wikipedia.org/wiki/Immediate_mode for more information.-vbo_rendering 0/1 = use OpenGL 1.4+ Vertex Buffer Objects for rendering (default: disabled)Note: the use of VBOs will enable the visualization of larger datasets at the expense of extra RAM.See http://en.wikipedia.org/wiki/Vertex_Buffer_Object for more information.-use_point_picking = enable the usage of picking points on screen (default disabled)-optimal_label_colors = maps existing labels to the optimal sequential glasbey colors, label_ids will not be mapped to fixed colors (default disabled)(Note: for multiple .pcd files, provide multiple -{fc,ps,opaque,position,orientation} parameters; they will be automatically assigned to the right file)
可以了,只是没有对应的.pcd文件,显示不出来。
接着:pcl_viewer fragment.pcd 可以对.pcd文件进行可视化,具体显示图像,如下所示。
> Loading fragment.pcd [done, 85 ms : 113662 points]
Available dimensions: x y z rgb normal_x normal_y normal_z curvature
在命令框中可以完成该工作,但是操作不方便,使用QT作为IDE吧,PCL在QT中稍微配置下就好:
QT += core
QT -= guiCONFIG += c++11TARGET = test
CONFIG += console
CONFIG -= app_bundleTEMPLATE = appSOURCES += main.cpp# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0#Opencv的配置
INCLUDEPATH += /usr/local/include\
/usr/local/include/opencv\
/usr/local/include/opencv2LIBS += /usr/local/lib/libopencv_highgui.so \/usr/local/lib/libopencv_core.so \/usr/local/lib/libopencv_imgproc.so \/usr/local/lib/libopencv_imgcodecs.so#PCL的配置
#Eigen
INCLUDEPATH += /usr/include/eigen3#Vtk
INCLUDEPATH += /usr/include/vtk-6.3LIBS += /usr/lib/x86_64-linux-gnu/libvtk*.so#Boost
INCLUDEPATH += /usr/include/boostLIBS += /usr/lib/x86_64-linux-gnu/libboost_*.so#PCL Header
INCLUDEPATH += /usr/include/pcl-1.8#PCL Lib
LIBS += /usr/lib/x86_64-linux-gnu/libpcl*.so
这里我还使用了opencv,所以会有opencv的配置,不需要的话,直接把opencv库的配置去掉即可。
测试代码:
#include <iostream>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
using namespace std;int user_data;void
viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{viewer.setBackgroundColor (1.0, 0.5, 1.0);pcl::PointXYZ o;o.x = 1.0;o.y = 0;o.z = 0;viewer.addSphere (o, 0.25, "sphere", 0);std::cout << "i only run once" << std::endl;}void
viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{static unsigned count = 0;std::stringstream ss;ss << "Once per viewer loop: " << count++;viewer.removeShape ("text", 0);viewer.addText (ss.str(), 200, 300, "text", 0);//FIXME: possible race condition here:user_data++;
}int
main ()
{pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);pcl::io::loadPCDFile ("five_people.pcd", *cloud);pcl::visualization::CloudViewer viewer("Cloud Viewer");//blocks until the cloud is actually renderedviewer.showCloud(cloud);//use the following functions to get access to the underlying more advanced/powerful//PCLVisualizer//This will only get called onceviewer.runOnVisualizationThreadOnce (viewerOneOff);//This will get called once per visualization iterationviewer.runOnVisualizationThread (viewerPsycho);while (!viewer.wasStopped ()){//you can also do cool processing here//FIXME: Note that this is running in a separate thread from viewerPsycho//and you should guard against race conditions yourself...user_data++;}return 0;
}
测试结果: