PCL学习笔记一:io

          最近结合例子学习(PCL)点云库的技术文档,今天开始把学习的过程记录下来,稍后会把PCL环境搭建的过程也分享出来,与大家共同学习。

学习的资源基本来自于PCL官网技术文档 。分为下面几个部分来学习PCL:

  •  io, image_range
  •  registration
  •  filters, features, keypoints
  •  segmentation
  •  surface
  •  kdtree, octree
  •  visualization

第一部分:io

 

PCD格式:

3D点云存储的一种格式。PCD(Point Cloud Data)格式原来就存在,PCL中改进了原有版本,使用的是0.7版本PCD_V7)。其他3D格式还有PLYpolygon文件格式),STL (主要用于CAD)等。 PCD格式头文件用ASCII编码,其内容每点之间都用”\n”换行隔开。

PCD文件中重要的入口参量有FIELDS(定义每一点所具有的所有维度),WIDTH(每行多少点),HEIGHT(多少行)。FIELDS示例:

FIELDS x y z                                                                 # XYZ data                                                                                             FIELDS x y z rgb                                                          # XYZ + colors                                                                                          FIELDS x y z normal_x normal_y normal_z              # XYZ + surface normals                                                                      FIELDS j1 j2 j3                                                              # moment invariants

写入PCD格式示例

读出PCD格式示例

         本人试了一下在VS中运行写入示例程序,加入包含文件和库文件,动态链接库之后,运行时还是出现了问题(PCDwrite.exe 中的 0x75b1969b 处有未经处理的异常: 0xC06D007E: Module not found),尚未解决。

连接两个点云  

保证两个点云的点field类型和数量相等,即可连接。

 连接点:直接相加。    cloud_c  = cloud_a;     cloud_c += cloud_b;

结果:

Cloud A:

    0.352222 -0.151883 -0.106395

    -0.397406 -0.473106 0.292602

    -0.731898 0.667105 0.441304

    -0.734766 0.854581 -0.0361733

    -0.4607 -0.277468 -0.916762

Cloud B:

    0.183749 0.968809 0.512055

    -0.998983 -0.463871 0.691785

    0.716053 0.525135 -0.523004

Cloud C:

    0.352222 -0.151883 -0.106395

    -0.397406 -0.473106 0.292602

    -0.731898 0.667105 0.441304

    -0.734766 0.854581 -0.0361733

    -0.4607 -0.277468 -0.916762

    0.183749 0.968809 0.512055

    -0.998983 -0.463871 0.691785

    0.716053 0.525135 -0.523004

 连接field:  pcl::concatenateFields (cloud_a, n_cloud_b, p_n_cloud_c);

结果:

Cloud A:

    0.352222 -0.151883 -0.106395

    -0.397406 -0.473106 0.292602

    -0.731898 0.667105 0.441304

    -0.734766 0.854581 -0.0361733

    -0.4607 -0.277468 -0.916762

Cloud B:

    0.183749 0.968809 0.512055

    -0.998983 -0.463871 0.691785

    0.716053 0.525135 -0.523004

    0.439387 0.56706 0.905417

    -0.579787 0.898706 -0.504929

Cloud C:

    0.352222 -0.151883 -0.106395 0.183749 0.968809 0.512055

    -0.397406 -0.473106 0.292602 -0.998983 -0.463871 0.691785

    -0.731898 0.667105 0.441304 0.716053 0.525135 -0.523004

    -0.734766 0.854581 -0.0361733 0.439387 0.56706 0.905417

    -0.4607 -0.277468 -0.916762 -0.579787 0.898706 -0.504929

OpenNI Grabber接口      

PCL提供了获取3D点的硬件接口,其中就包括了能驱动Microsoft  Kinect 和 Asus Xtion ProOpenNI Grabber。

#include <pcl/io/openni_grabber.h>
 #include <pcl/visualization/cloud_viewer.h>
 class SimpleOpenNIViewer
 {
   public:
     SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
     {
       if (!viewer.wasStopped())
         viewer.showCloud (cloud);
     }
     void run ()
     {
       pcl::Grabber* interface = new pcl::OpenNIGrabber();
       // make callback function from member function
       boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
         boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
       interface->registerCallback (f);
        // start receiving point clouds
       interface->start ();
       // wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1);
       while (!viewer.wasStopped())
       {
         boost::this_thread::sleep (boost::posix_time::seconds (1));
       }
       // stop the grabber
       interface->stop ();
     }
     pcl::visualization::CloudViewer viewer;
 };

 int main ()
 {
   SimpleOpenNIViewer v;
   v.run ();
   return 0;
 }

运行Tools and Demo下的pcl_openni_viewer项目的结果:

上面例子的拓展,把深度和色彩值结合,显示在三维坐标空间中

PCL学习笔记一:io_第1张图片

直接在环境里面找到tutorial文件夹下的源代码,在原路径下Cmake生成解决方案,再编译。 如,源代码处选择D:/PCL/trunk/doc/tutorials/content/sources/range_image_border_extraction,目标代码处选择D:/PCL/trunk/doc/tutorials/content/sources/range_image_border_extraction。单击Configure,弹出对话框选择VS10Use default native compliers,完成后展开窗口内红色分组确认每个安装过的第三方includelib都正确后,点击Generate

关闭Cmake Gui,打开生成的sln,加入如下动态链接库。还是出现和之前一样的问题。module not found.

XnCore.dll

XnDDK.dll

XnDeviceFile.dll

XnDeviceSensorV2KM.dll

XnFormats.dll

你可能感兴趣的:(3D,PCL)