File: normal_estimation_using_integral_images.rst

package info (click to toggle)
pcl 1.7.2-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 138,052 kB
  • ctags: 39,618
  • sloc: cpp: 446,687; xml: 28,552; ansic: 13,753; python: 539; makefile: 72; sh: 25
file content (112 lines) | stat: -rw-r--r-- 3,226 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
.. _normal_estimation_using_integral_images:

Normal Estimation Using Integral Images
---------------------------------------

In this tutorial we will learn how to compute normals for an organized point
cloud using integral images. 


The code
--------

First, create a file, let's say, ``normal_estimation_using_integral_images.cpp`` in your favorite
editor, and place the following inside it:

.. code-block:: cpp
   :linenos:

	#include <pcl/io/io.h>
	#include <pcl/io/pcd_io.h>
	#include <pcl/features/integral_image_normal.h>
	#include <pcl/visualization/cloud_viewer.h>
		
	int 
	main ()
	{
		// load point cloud
		pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
		pcl::io::loadPCDFile ("table_scene_mug_stereo_textured.pcd", *cloud);
		
		// estimate normals
		pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);

		pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
		ne.setNormalEstimationMethod (ne.AVERAGE_3D_GRADIENT);
		ne.setMaxDepthChangeFactor(0.02f);
		ne.setNormalSmoothingSize(10.0f);
		ne.setInputCloud(cloud);
		ne.compute(*normals);

		// visualize normals
		pcl::visualization::PCLVisualizer viewer("PCL Viewer");
		viewer.setBackgroundColor (0.0, 0.0, 0.5);
		viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, normals);
		
		while (!viewer.wasStopped ())
		{
		  viewer.spinOnce ();
		}
		return 0;
	}

The explanation
---------------

Now, let's break down the code piece by piece. In the first part we load a
point cloud from a file:

.. code-block:: cpp

	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
	pcl::io::loadPCDFile ("table_scene_mug_stereo_textured.pcd", *cloud);

In the second part we create an object for the normal estimation and compute
the normals:

.. code-block:: cpp

	// estimate normals
	pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);

	pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
	ne.setNormalEstimationMethod (ne.AVERAGE_3D_GRADIENT);
	ne.setMaxDepthChangeFactor(0.02f);
	ne.setNormalSmoothingSize(10.0f);
	ne.setInputCloud(cloud);
	ne.compute(*normals);

The following normal estimation methods are available:

.. code-block:: cpp

     enum NormalEstimationMethod
     {
       COVARIANCE_MATRIX,
       AVERAGE_3D_GRADIENT,
       AVERAGE_DEPTH_CHANGE
     };
	 
The COVARIANCE_MATRIX mode creates 9 integral images to compute the normal for
a specific point from the covariance matrix of its local neighborhood. The
AVERAGE_3D_GRADIENT mode creates 6 integral images to compute smoothed versions
of horizontal and vertical 3D gradients and computes the normals using the
cross-product between these two gradients. The AVERAGE_DEPTH_CHANGE mode
creates only a single integral image and computes the normals from the average
depth changes.

In the last part we visualize the point cloud and the corresponding normals:

.. code-block:: cpp

	// visualize normals
	pcl::visualization::PCLVisualizer viewer("PCL Viewer");
	viewer.setBackgroundColor (0.0, 0.0, 0.5);
	viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, normals);
	
	while (!viewer.wasStopped ())
	{
	  viewer.spinOnce ();
	}