Transcription of PCL Tutorial: - The Point Cloud Library By Example
1 PCL Tutorial: The Point Cloud Library By ExampleJeff DelmericoVision and Perceptual Machines Lab106 Davis HallUB North 11, 2013 Jeff DelmericoFebruary 11, 20131/38 Point CloudsDefinitionA Point Cloud is a data structure used to represent a collection ofmulti-dimensional points and is commonly used to representthree-dimensional a 3D Point Cloud , the points usually represent the X, Y, and Zgeometric coordinates of an underlying sampled surface. Whencolor information is present, the Point Cloud becomes DelmericoFebruary 11, 2013 Introduction2/38 Where do Point clouds come from?IRGB-D camerasIStereo camerasI3D laser scannersITime-of-flight camerasISythetically from software( Blender)Jeff DelmericoFebruary 11, 2013 Introduction3/38 Point Cloud LibraryIPCL is a large scale, open project for 2D/3D image and pointcloud processing (in C++, w/ new python bindings).IThe PCL framework contains numerous state-of-the artalgorithms including filtering, feature estimation, surfacereconstruction, registration, model fitting and is cross-platform, and has been successfully compiled anddeployed on Linux, MacOS, Windows, and DelmericoFebruary 11, 2013 Introduction4/38 Getting PCLIF irst, download PCL for your system from: you want to try the python bindings (currently for only asubset of the full PCL functionality), go here: provides the 3D processing pipeline for ROS, so you canalso get the perceptionpcl stack and still use PCL depends on Boost, Eigen, FLANN, and DelmericoFebruary 11, 2013 Using PCL5/38 Basic StructuresThe basic data type in PCL is a PointCloud.
2 A PointCloud is atemplated C++ class which contains the following data fields:Iwidth (int)- secifies the width of the Point Cloud dataset inthe number of total number of points in the Cloud (equal with thenumber of elements in points ) for unorganized datasetsIthe width (total number of points in a row) of an organizedpoint Cloud datasetIheight (int)- Specifies the height of the Point Cloud datasetin the number of to1for unorganized Point cloudsIthe height (total number of rows) of an organized Point clouddatasetIpoints (std::vector PointT )- Contains the data arraywhere all the points of type PointT are DelmericoFebruary 11, 2013 Using PCL6/38 Basic StructuresIisdense (bool)- Specifies if all the data inpointsis finite(true), or whether the XYZ values of certain points mightcontain Inf/NaN values (false).Isensororigin(Eigen::Vector4f)- Specifies the sensoracquisition pose (origin/translation). This member is usuallyoptional, and not used by the majority of the algorithms (Eigen::Quaternionf)- Specifies thesensor acquisition pose (orientation).
3 This member is usuallyoptional, and not used by the majority of the algorithms DelmericoFebruary 11, 2013 Using PCL7/38 Point TypesIPointXYZ- float x, y, zIPointXYZI- float x, y, z, intensityIPointXYZRGB- float x, y, z, rgbIPointXYZRGBA- float x, y, z, uint32t rgbaINormal- float normal[3], curvatureIPointNormal- float x, y, z, normal[3], curvatureIHistogram- float histogram[N]IAnd many, many, more. Plus you can define new types to suityour DelmericoFebruary 11, 2013 Using PCL8/38 Building PCL ProjectsPCL relies onCMakeas a build tool. CMake just requires thatyou place a file on your (VERSION FATALERROR)project(MYGRANDPROJECT)findpa ckage(PCL REQUIRED COMPONENTS common io)includedirectories($PCLINCLUDEDIRS)li nkdirectories($PCLLIBRARYDIRS)adddefinit ions($PCLDEFINITIONS)addexecutable(pcdwr itetest )targetlinklibraries(pcdwritetest $PCLCOMMONLIBRARIES$PCLIOLIBRARIES)Jeff DelmericoFebruary 11, 2013 Using PCL9/38 Building PCL ProjectsGenerating the Makefile & Building the Project$cd /PATH/TO/MY/GRAND/PROJECT$ mkdir build$ cd build$ cmake.
4 $ makeJeff DelmericoFebruary 11, 2013 Using PCL10/38 PCD File FormatA simple file format for storing multi-dimensional Point data. Itconsists of a text header (with the fields below), followed by thedata in ASCII (w/ points on separate lines) or binary (a memorycopy of thepointsvector of the PC).IVERSION - the PCD file version (usually .7)IFIELDS - the name of each dimension/field that a Point can have ( FIELDSx y z )ISIZE - the size of each dimension in bytes ( a float is 4)ITYPE - the type of each dimension as a char (I= signed,U= unsigned,F=float)ICOUNT - the number of elements in each dimension ( x, y, or z would onlyhave 1, but a histogram would haveN)IWIDTH - the width of the Point cloudIHEIGHT - the height of the Point cloudIVIEWPOINT - an acquisition viewpoint for the points : translation (tx ty tz) +quaternion (qw qx qy qz)IPOINTS - the total number of points in the cloudIDATA - the data type that the Point Cloud data is stored in (asciiorbinary)Jeff DelmericoFebruary 11, 2013I/O11/38 PCD Example #.
5 PCD - Point Cloud Data file formatVERSION .7 FIELDS x y z rgbSIZE 4 4 4 4 TYPE F F F FCOUNT 1 1 1 1 WIDTH 213 HEIGHT 1 VIEWPOINT 0 0 0 1 0 0 0 points 213 DATA 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + DelmericoFebruary 11, 2013I/O12/38 Writing PCD #i n c l u d e<p c l / i o / p c di o . h>#i n c l u d e<p c l / p o i n tt y p e s . h>i n tm a i n (i n ta r g c ,c h a r a r g v ){p c l : : P o i n t C l o u d<p c l : : PointXYZ>c l o u d ;// F i l l in the Cloud datac l o u d . w i d t h= 5 0 ;c l o u d . h e i g h t= 1 ;c l o u d . i sd e n s e =f a l s e;c l o u d . p o i n t s . r e s i z e ( c l o u d . w i d t h c l o u d . h e i g h t ) ;f o r( s i z eti = 0 ; i<c l o u d . p o i n t s . s i z e( ) ; ++i ){c l o u d . p o i n t s [ i ] . x = 1 0 2 4 r a n d ( ) / (RANDMAX + 1 . 0 f ) ;c l o u d . p o i n t s [ i ] . y = 1 0 2 4 r a n d ( ) / (RANDMAX + 1.)}}
6 0 f ) ;c l o u d . p o i n t s [ i ] . z = 1 0 2 4 r a n d ( ) / (RANDMAX + 1 . 0 f ) ;}p c l : : i o : : s a v e P C D F i l e A S C I I ( t e s tp c d . p c d , c l o u d ) ;r e t u r n( 0 ) ;}Jeff DelmericoFebruary 11, 2013I/O13/38 Reading PCD #i n c l u d e<p c l / i o / p c di o . h>#i n c l u d e<p c l / p o i n tt y p e s . h>i n tm a i n (i n ta r g c ,c h a r a r g v ){p c l : : P o i n t C l o u d<p c l : : PointXYZ>: : P t r c l o u d (newp c l : : P o i n t C l o u d<p c l : : PointXYZ>);// Load the f i l ei f( p c l : : i o : : l o a d P C D F i l e<p c l : : PointXYZ>( t e s tp c d . p c d , c l o u d ) == 1){PCLERROR ( C o u l d n tr e a df i l et e s tp c d . p c d\n ) ;r e t u r n( 1 ) ;}// Do some p r o c e s s i n g on the Cloud herer e t u r n( 0 ) ;}Jeff DelmericoFebruary 11, 2013I/O14/38 Getting Point Clouds from #i n c l u d e<p c l / i o / o p e n n ig r a b b e r.
7 H>#i n c l u d e<p c l / v i s u a l i z a t i o n / c l o u dv i e w e r . h>c l a s sS i m p l e O p e n N I V i e w e r{p u b l i c:S i m p l e O p e n N I V i e w e r ( ) : v i e w e r ( PCLOpenNIV i e w e r ){}v o i dc l o u dc b(c o n s tp c l : : P o i n t C l o u d<p c l : : PointXYZRGBA>: : C o n s t P t r &c l o u d ){i f( ! v i e w e r . w a s S t o p p e d ( ) )v i e w e r . s h o w C l o u d ( c l o u d ) ;}p c l : : v i s u a l i z a t i o n : : C l o u d V i e w e r v i e w e r ;Jeff DelmericoFebruary 11, 2013I/O15/38 Getting Point Clouds from o i dr u n ( ){p c l : : G r a b b e r i n t e r f a c e =newp c l : : O p e n N I G r a b b e r ( ) ;b o o s t : : f u n c t i o n<v o i d(c o n s tp c l : : P o i n t C l o u d<p c l : : PointXYZRGBA>: : C o n s t P t r&)>f =b o o s t : : b i n d (& S i m p l e O p e n N I V i e w e r : : c l o u dc b,t h i s,1 ) ;i n t e r f a c e >r e g i s t e r C a l l b a c k ( f ) ;i n t e r f a c e >s t a r t( ) ;w h i l e( !)}}
8 V i e w e r . w a s S t o p p e d ( ) ){b o o s t : : t h i st h r e a d : : s l e e p ( b o o s t : : p o s i xt i m e : : s e c o n d s ( 1 ) ) ;}i n t e r f a c e >s t o p ( ) ;}};i n tm a i n ( ){S i m p l e O p e n N I V i e w e r v ;v . r u n ( ) ;r e t u r n0 ;}Jeff DelmericoFebruary 11, 2013I/O16/38 Normal o i dd o w n s a m p l e ( p c l : : P o i n t C l o u d<p c l : : PointXYZRGB>: : P t r &p o i n t s ,f l o a tl e a fs i z e ,p c l : : P o i n t C l o u d<p c l : : PointXYZRGB>: : P t r &d o w n s a m p l e do u t ){p c l : : V o x e l G r i d<p c l : : PointXYZRGB>v o xg r i d ;v o xg r i d . s e t L e a f S i z e ( l e a fs i z e , l e a fs i z e ,l e a fs i z e ) ;v o xg r i d . s e t I n p u t C l o u d ( p o i n t s ) ;v o xg r i d . f i l t e r ( d o w n s a m p l e do u t ) ;}v o i dc o m p u t es u r f a c en o r m a l s ( p c l : : P o i n t C l o u d<p c l : : PointXYZRGB>: : P t r &p o i n t s ,f l o a tn o r m a lr a d i u s , p c l : : P o i n t C l o u d<p c l : : Normal>: : P t r &n o r m a l so u t ){p c l : : N o r m a l E s t i m a t i o n<p c l : : PointXYZRGB , p c l : : Normal>n o r me s t ;// Use a FLANN based KdTree to perform neighborhood s e a r c h e sn o r me s t.
9 S e t S e a r c h M e t h o d ( p c l : : s e a r c h : : KdTree<p c l : : PointXYZRGB>: : P t r(newp c l : : s e a r c h : : KdTree<p c l : : PointXYZRGB>) ) ;// S p e c i f y the l o c a l neighborhood s i z e f o r computing the s u r f a c e normalsn o r me s t . s e t R a d i u s S e a r c h ( n o r m a lr a d i u s ) ;// Set the input p o i n t sn o r me s t . s e t I n p u t C l o u d ( p o i n t s ) ;// Estimate the s u r f a c e normals and s t o r e the r e s u l t in normalsout n o r me s t . c o m p u t e ( n o r m a l so u t ) ;}Jeff DelmericoFebruary 11, 20133D Features17 o i dv i s u a l i z en o r m a l s (c o n s tp c l : : P o i n t C l o u d<p c l : : PointXYZRGB>: : P t r p o i n t s ,c o n s tp c l : : P o i n t C l o u d<p c l : : PointXYZRGB>: : P t r n o r m a lp o i n t s ,c o n s tp c l : : P o i n t C l o u d<p c l : : Normal>: : P t r n o r m a l s ){p c l : : v i s u a l i z a t i o n : : P C L V i s u a l i z e r v i z ;v i z.
10 A d d P o i n t C l o u d ( p o i n t s , p o i n t s ) ;v i z . a d d P o i n t C l o u d ( n o r m a lp o i n t s , n o r m a lp o i n t s ) ;v i z . a d d P o i n t C l o u d N o r m a l s<p c l : : PointXYZRGB , p c l : : Normal>( n o r m a lp o i n t s , n o r m a l s , 1 , 0 . 0 1 , n o r m a l s ) ;v i z . s p i n ( ) ;}i n tm a i n (i n ta r g c ,c h a r a r g v ){// Load data from pcd ..p c l : : P o i n t C l o u d<p c l : : PointXYZRGB>: : P t r d s (newp c l : : P o i n t C l o u d<p c l : : PointXYZRGB>);p c l : : P o i n t C l o u d<p c l : : Normal>: : P t r n o r m a l s (newp c l : : P o i n t C l o u d<p c l : : Normal>);// Downsample the cloudc o n s t f l o a tv o x e lg r i dl e a fs i z e = 0 . 0 1 ;d o w n s a m p l e ( c l o u d , v o x e lg r i dl e a fs i z e , d s ) ;// Compute s u r f a c e normalsc o n s t f l o a tn o r m a lr a d i u s = 0.