When I was learning PCL, I encountered an example. For the ordered point cloud , the integral image (Integral Image) operation can be performed . The point cloud library provides 4 implementation methods:
COVARIANCE_MATRIX, //局部协方差矩阵,建立9个积分图来计算法线
AVERAGE_3D_GRADIENT,//创建6个积分图来计算水平垂直方向平滑后的三维梯度
AVERAGE_DEPTH_CHANGE,//创建1个单一积分图,并从深度变化计算法线
SIMPLE_3D_GRADIENT //
You can compare the effects of the first three and consolidate to achieve multi-window display.
code snippet:
#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})
The output is:
Summarize:
(1) Key functions:
void pcl::IntegralImageNormalEstimation< PointInT, PointOutT >::setNormalEstimationMethod(NormalEstimationMethod normal_estimation_method)
(2) Understanding of multi-window contrast display
function:
void pcl::visualization::PCLVisualizer::createViewPort | ( | double | xmin , |
double | ymin , | ||
double | xmax , | ||
double | ymax , | ||
int & | viewport | ||
) |
Among them, the maximum and minimum values of x and y are commonly understood as the proportion of the window from xx to xx. In this three comparisons, x is divided into three equal parts. y is still 0~1.
function:
addText has three overloads:
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 |
||
) |
colored text
with size and color
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 |
||
) |