PCL点云库,特征描述提取积分图(Integral Image)

在学习PCL的时候,遇到了一个例子,对于有序点云可以进行积分图(Integral Image)操作,点云库提供了4种实现的方法:

        COVARIANCE_MATRIX, //局部协方差矩阵,建立9个积分图来计算法线
        AVERAGE_3D_GRADIENT,//创建6个积分图来计算水平垂直方向平滑后的三维梯度
        AVERAGE_DEPTH_CHANGE,//创建1个单一积分图,并从深度变化计算法线
        SIMPLE_3D_GRADIENT //

 可以对比一下前三种的效果并巩固一下实现多窗口显示。

代码段:

 #include <pcl/io/io.h>
 #include <pcl/io/pcd_io.h>
 #include <pcl/features/integral_image_normal.h>//Integral images 
 #include <pcl/visualization/cloud_viewer.h>
     int
     main ()
     {
             //set up cloud
             pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
             pcl::io::loadPCDFile ("table_scene_mug_stereo_textured.pcd", *cloud);
             //set up normal
             pcl::PointCloud<pcl::Normal>::Ptr normals_1 (new pcl::PointCloud<pcl::Normal>);
             pcl::PointCloud<pcl::Normal>::Ptr normals_2 (new pcl::PointCloud<pcl::Normal>);
             pcl::PointCloud<pcl::Normal>::Ptr normals_3 (new pcl::PointCloud<pcl::Normal>);
             std::vector<pcl::PointCloud<pcl::Normal>::Ptr> NormalPt {normals_1,normals_2,normals_3};

             pcl::IntegralImageNormalEstimation<pcl::PointXYZ,pcl::Normal> ne_1;
             pcl::IntegralImageNormalEstimation<pcl::PointXYZ,pcl::Normal> ne_2;
             pcl::IntegralImageNormalEstimation<pcl::PointXYZ,pcl::Normal> ne_3;

               ne_1.setInputCloud(cloud);
               ne_2.setInputCloud(cloud);
               ne_3.setInputCloud(cloud);
               ne_1.setNormalEstimationMethod (ne_1.AVERAGE_3D_GRADIENT);
               ne_2.setNormalEstimationMethod (ne_2.COVARIANCE_MATRIX);
               ne_3.setNormalEstimationMethod (ne_3.AVERAGE_DEPTH_CHANGE);
               ne_1.setMaxDepthChangeFactor(0.02f);
               ne_1.setNormalSmoothingSize(10.0f);
               ne_1.compute(*NormalPt[0]);
               ne_2.setMaxDepthChangeFactor(0.02f);
               ne_2.setNormalSmoothingSize(10.0f);
               ne_2.compute(*NormalPt[1]);
               ne_3.setMaxDepthChangeFactor(0.02f);
               ne_3.setNormalSmoothingSize(10.0f);
               ne_3.compute(*NormalPt[2]);

              // std::vector<pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal>> ne {ne_1,ne_2,ne_3};

            //visualization
             pcl::visualization::PCLVisualizer viewer("PCL Viewer");
             viewer.initCameraParameters();
             int v1 (0);
             int v2 (0);
             int v3 (0);
            //分割窗口
             viewer.createViewPort(0,0,0.3333,1,v1);
             viewer.setBackgroundColor (0.0, 0.0, 0.5,v1);
             viewer.addText("AVERAGE_3D_GRADIENT",10,10,"v1",v1);
             viewer.createViewPort(0.3333,0.0,0.6666,1,v2);
             viewer.setBackgroundColor (0.3, 0.3, 0.5,v2);
             viewer.addText("COVARIANCE_MATRIX",10,10,"v2",v2);
             viewer.createViewPort(0.66666,0,1,1,v3);
             viewer.setBackgroundColor (0.6, 0.3, 0.1,v3);
             viewer.addText("AVERAGE_DEPTH_CHANGE",10,10,"v3",v3);
             //viewer.addPointCloud<pcl::PointXYZ>(cloud,"cloud1",v1);
             //viewer.addPointCloud<pcl::PointXYZ>(cloud,"cloud2",v2);
             //viewer.addPointCloud<pcl::PointXYZ>(cloud,"cloud3",v3);
             viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, normals_1,100,0.05f,"normals_1",v1);
             viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, normals_2,100,0.05f,"normals_2",v2);
             viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, normals_3,100,0.05f,"normals_3",v3);

             while (!viewer.wasStopped ())
             {
               viewer.spinOnce ();
             }
             return 0;
     }

CMakeLists:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(normal_estimation_using_integral_images)
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})	
add_executable (normal_estimation_using_integral_images normal_estimation_using_integral_images.cpp)
target_link_libraries (normal_estimation_using_integral_images ${PCL_LIBRARIES})

 

输出结果为:

总结:

(1)关键函数:

void pcl::IntegralImageNormalEstimation< PointInT, PointOutT >::setNormalEstimationMethod(NormalEstimationMethod normal_estimation_method)

 (2)关于多窗口对比显示的理解

 函数:

void pcl::visualization::PCLVisualizer::createViewPort ( double  xmin,
double  ymin,
double  xmax,
double  ymax,
int &  viewport 
)

 其中x,y最大最小值通俗的理解为在窗口所占的比例从xx到xx。本次三个对比故对x进行三等分。y仍然为0~1。

函数:

addText则有三个重载:

addText() [1/3]

bool pcl::visualization::PCLVisualizer::addText ( const std::string &  text,
int  xpos,
int  ypos,
const std::string &  id = "",
int  viewport = 0 
)

 

addText() [2/3]

bool pcl::visualization::PCLVisualizer::addText ( const std::string &  text,
int  xpos,
int  ypos,
double  r,
double  g,
double  b,
const std::string &  id = "",
int  viewport = 0 
)

 带颜色的文字

 

 带大小以及颜色的

addText() [3/3]

bool pcl::visualization::PCLVisualizer::addText ( const std::string &  text,
int  xpos,
int  ypos,
int  fontsize,
double  r,
double  g,
double  b,
const std::string &  id = "",
int  viewport = 0 
)

 

猜你喜欢

转载自blog.csdn.net/m0_46611008/article/details/125052879