Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drawing Point Cloud retrieve from Velodyne VLP-16
cmake_minimum_required( VERSION 2.8 )
# Create Project
project( solution )
add_executable( project main.cpp )
# Set StartUp Project (Option)
# (This setting is able to enable by using CMake 3.6.0 RC1 or later.)
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" )
# Find Packages
find_package( PCL 1.8 REQUIRED )
if( PCL_FOUND )
# [C/C++]>[General]>[Additional Include Directories]
include_directories( ${PCL_INCLUDE_DIRS} )
# [C/C++]>[Preprocessor]>[Preprocessor Definitions]
add_definitions( ${PCL_DEFINITIONS} )
# For Use Not PreCompiled Features
#add_definitions( -DPCL_NO_PRECOMPILE )
# [Linker]>[General]>[Additional Library Directories]
link_directories( ${PCL_LIBRARY_DIRS} )
# [Linker]>[Input]>[Additional Dependencies]
target_link_libraries( project ${PCL_LIBRARIES} )
endif()
#include <iostream>
#include <string>
#include <vector>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/vlp_grabber.h>
#include <pcl/console/parse.h>
#include <pcl/visualization/pcl_visualizer.h>
// Point Type
// pcl::PointXYZ, pcl::PointXYZI, pcl::PointXYZRGBA
typedef pcl::PointXYZI PointType;
int main( int argc, char *argv[] )
{
// Command-Line Argument Parsing
if( pcl::console::find_switch( argc, argv, "-help" ) ){
std::cout << "usage: " << argv[0]
<< " [-ipaddress <192.168.1.70>]"
<< " [-port <2368>]"
<< " [-pcap <*.pcap>]"
<< " [-help]"
<< std::endl;
return 0;
}
std::string ipaddress( "192.168.1.70" );
std::string port( "2368" );
std::string pcap;
pcl::console::parse_argument( argc, argv, "-ipaddress", ipaddress );
pcl::console::parse_argument( argc, argv, "-port", port );
pcl::console::parse_argument( argc, argv, "-pcap", pcap );
std::cout << "-ipadress : " << ipaddress << std::endl;
std::cout << "-port : " << port << std::endl;
std::cout << "-pcap : " << pcap << std::endl;
// Point Cloud
pcl::PointCloud<PointType>::ConstPtr cloud;
// PCL Visualizer
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer( new pcl::visualization::PCLVisualizer( "Velodyne Viewer" ) );
viewer->addCoordinateSystem( 3.0, "coordinate" );
viewer->setBackgroundColor( 0.0, 0.0, 0.0, 0 );
viewer->initCameraParameters();
viewer->setCameraPosition( 0.0, 0.0, 30.0, 0.0, 1.0, 0.0, 0 );
// Point Cloud Color Hndler
pcl::visualization::PointCloudColorHandler<PointType>::Ptr handler;
const std::type_info& type = typeid( PointType );
if( type == typeid( pcl::PointXYZ ) ){
std::vector<double> color = { 255.0, 255.0, 255.0 };
boost::shared_ptr<pcl::visualization::PointCloudColorHandlerCustom<PointType>> color_handler( new pcl::visualization::PointCloudColorHandlerCustom<PointType>( color[0], color[1], color[2] ) );
handler = color_handler;
}
else if( type == typeid( pcl::PointXYZI ) ){
boost::shared_ptr<pcl::visualization::PointCloudColorHandlerGenericField<PointType>> color_handler( new pcl::visualization::PointCloudColorHandlerGenericField<PointType>( "intensity" ) );
handler = color_handler;
}
else if( type == typeid( pcl::PointXYZRGBA ) ){
boost::shared_ptr<pcl::visualization::PointCloudColorHandlerRGBField<PointType>> color_handler( new pcl::visualization::PointCloudColorHandlerRGBField<PointType>() );
handler = color_handler;
}
else{
throw std::runtime_error( "This PointType is unsupported." );
}
// Retrieved Point Cloud Callback Function
boost::mutex mutex;
boost::function<void( const pcl::PointCloud<PointType>::ConstPtr& )> function =
[ &cloud, &mutex ]( const pcl::PointCloud<PointType>::ConstPtr& ptr ){
boost::mutex::scoped_lock lock( mutex );
/* Point Cloud Processing */
cloud = ptr;
};
// VLP Grabber
boost::shared_ptr<pcl::VLPGrabber> grabber;
if( !pcap.empty() ){
std::cout << "Capture from PCAP..." << std::endl;
grabber = boost::shared_ptr<pcl::VLPGrabber>( new pcl::VLPGrabber( pcap ) );
}
else if( !ipaddress.empty() && !port.empty() ){
std::cout << "Capture from Sensor..." << std::endl;
grabber = boost::shared_ptr<pcl::VLPGrabber>( new pcl::VLPGrabber( boost::asio::ip::address::from_string( ipaddress ), boost::lexical_cast<unsigned short>( port ) ) );
}
// Register Callback Function
boost::signals2::connection connection = grabber->registerCallback( function );
// Start Grabber
grabber->start();
while( !viewer->wasStopped() ){
// Update Viewer
viewer->spinOnce();
boost::mutex::scoped_try_lock lock( mutex );
if( lock.owns_lock() && cloud ){
// Update Point Cloud
handler->setInputCloud( cloud );
if( !viewer->updatePointCloud( cloud, *handler, "cloud" ) ){
viewer->addPointCloud( cloud, *handler, "cloud" );
}
}
}
// Stop Grabber
grabber->stop();
// Disconnect Callback Function
if( connection.connected() ){
connection.disconnect();
}
return 0;
}
@shaikhibrahim951

This comment has been minimized.

Show comment
Hide comment
@shaikhibrahim951

shaikhibrahim951 Jul 20, 2017

Hi, I am new to PCL and try to execute your code on linux 14.04. But it is giving me error like below.
First I did cmake ..

user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ cmake ..
-- Boost version: 1.54.0
-- Found the following Boost libraries:
--   system
--   filesystem
--   thread
--   date_time
--   iostreams
--   serialization
-- checking for module 'libopenni2'
--   package 'libopenni2' not found
-- Could NOT find OpenNI2 (missing:  OPENNI2_LIBRARY OPENNI2_INCLUDE_DIRS) 
** WARNING ** io features related to openni2 will be disabled
-- Could NOT find ensenso (missing:  ENSENSO_LIBRARY ENSENSO_INCLUDE_DIR) 
** WARNING ** io features related to ensenso will be disabled
-- Could NOT find DAVIDSDK (missing:  DAVIDSDK_LIBRARY DAVIDSDK_INCLUDE_DIR) 
** WARNING ** io features related to davidSDK will be disabled
-- Could NOT find DSSDK (missing:  _DSSDK_LIBRARIES) 
** WARNING ** io features related to dssdk will be disabled
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
** WARNING ** io features related to libusb-1.0 will be disabled
-- checking for module 'libopenni2'
--   package 'libopenni2' not found
-- Could NOT find OpenNI2 (missing:  OPENNI2_LIBRARY OPENNI2_INCLUDE_DIRS) 
** WARNING ** visualization features related to openni2 will be disabled
-- Could NOT find ensenso (missing:  ENSENSO_LIBRARY ENSENSO_INCLUDE_DIR) 
** WARNING ** visualization features related to ensenso will be disabled
-- Could NOT find DAVIDSDK (missing:  DAVIDSDK_LIBRARY DAVIDSDK_INCLUDE_DIR) 
** WARNING ** visualization features related to davidSDK will be disabled
-- Could NOT find DSSDK (missing:  _DSSDK_LIBRARIES) 
** WARNING ** visualization features related to dssdk will be disabled
-- Could NOT find RSSDK (missing:  _RSSDK_LIBRARIES) 
** WARNING ** visualization features related to rssdk will be disabled
-- looking for PCL_COMMON
-- looking for PCL_OCTREE
-- looking for PCL_IO
-- looking for PCL_KDTREE
-- looking for PCL_SEARCH
-- looking for PCL_SAMPLE_CONSENSUS
-- looking for PCL_FILTERS
-- looking for PCL_2D
-- looking for PCL_FEATURES
-- looking for PCL_GEOMETRY
-- looking for PCL_KEYPOINTS
-- looking for PCL_SURFACE
-- looking for PCL_REGISTRATION
-- looking for PCL_ML
-- looking for PCL_SEGMENTATION
-- looking for PCL_RECOGNITION
-- looking for PCL_VISUALIZATION
-- looking for PCL_PEOPLE
-- looking for PCL_OUTOFCORE
-- looking for PCL_STEREO
-- looking for PCL_TRACKING
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/pcl/vlp_grabber/build
user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ 

Second I did make

user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ make
Scanning dependencies of target project
[100%] Building CXX object CMakeFiles/project.dir/main.cpp.o
/home/user/pcl/vlp_grabber/main.cpp: In function ‘int main(int, char**)’:
/home/user/pcl/vlp_grabber/main.cpp:90:9: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
         };
         ^
/home/user/pcl/vlp_grabber/main.cpp:90:9: error: conversion from ‘main(int, char**)::__lambda0’ to non-scalar type ‘boost::function<void(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&)>’ requested
make[2]: *** [CMakeFiles/project.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/project.dir/all] Error 2
make: *** [all] Error 2
user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ 

Kindly provide me proper solution so that I can work further.

Hi, I am new to PCL and try to execute your code on linux 14.04. But it is giving me error like below.
First I did cmake ..

user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ cmake ..
-- Boost version: 1.54.0
-- Found the following Boost libraries:
--   system
--   filesystem
--   thread
--   date_time
--   iostreams
--   serialization
-- checking for module 'libopenni2'
--   package 'libopenni2' not found
-- Could NOT find OpenNI2 (missing:  OPENNI2_LIBRARY OPENNI2_INCLUDE_DIRS) 
** WARNING ** io features related to openni2 will be disabled
-- Could NOT find ensenso (missing:  ENSENSO_LIBRARY ENSENSO_INCLUDE_DIR) 
** WARNING ** io features related to ensenso will be disabled
-- Could NOT find DAVIDSDK (missing:  DAVIDSDK_LIBRARY DAVIDSDK_INCLUDE_DIR) 
** WARNING ** io features related to davidSDK will be disabled
-- Could NOT find DSSDK (missing:  _DSSDK_LIBRARIES) 
** WARNING ** io features related to dssdk will be disabled
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
** WARNING ** io features related to libusb-1.0 will be disabled
-- checking for module 'libopenni2'
--   package 'libopenni2' not found
-- Could NOT find OpenNI2 (missing:  OPENNI2_LIBRARY OPENNI2_INCLUDE_DIRS) 
** WARNING ** visualization features related to openni2 will be disabled
-- Could NOT find ensenso (missing:  ENSENSO_LIBRARY ENSENSO_INCLUDE_DIR) 
** WARNING ** visualization features related to ensenso will be disabled
-- Could NOT find DAVIDSDK (missing:  DAVIDSDK_LIBRARY DAVIDSDK_INCLUDE_DIR) 
** WARNING ** visualization features related to davidSDK will be disabled
-- Could NOT find DSSDK (missing:  _DSSDK_LIBRARIES) 
** WARNING ** visualization features related to dssdk will be disabled
-- Could NOT find RSSDK (missing:  _RSSDK_LIBRARIES) 
** WARNING ** visualization features related to rssdk will be disabled
-- looking for PCL_COMMON
-- looking for PCL_OCTREE
-- looking for PCL_IO
-- looking for PCL_KDTREE
-- looking for PCL_SEARCH
-- looking for PCL_SAMPLE_CONSENSUS
-- looking for PCL_FILTERS
-- looking for PCL_2D
-- looking for PCL_FEATURES
-- looking for PCL_GEOMETRY
-- looking for PCL_KEYPOINTS
-- looking for PCL_SURFACE
-- looking for PCL_REGISTRATION
-- looking for PCL_ML
-- looking for PCL_SEGMENTATION
-- looking for PCL_RECOGNITION
-- looking for PCL_VISUALIZATION
-- looking for PCL_PEOPLE
-- looking for PCL_OUTOFCORE
-- looking for PCL_STEREO
-- looking for PCL_TRACKING
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/pcl/vlp_grabber/build
user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ 

Second I did make

user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ make
Scanning dependencies of target project
[100%] Building CXX object CMakeFiles/project.dir/main.cpp.o
/home/user/pcl/vlp_grabber/main.cpp: In function ‘int main(int, char**)’:
/home/user/pcl/vlp_grabber/main.cpp:90:9: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
         };
         ^
/home/user/pcl/vlp_grabber/main.cpp:90:9: error: conversion from ‘main(int, char**)::__lambda0’ to non-scalar type ‘boost::function<void(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&)>’ requested
make[2]: *** [CMakeFiles/project.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/project.dir/all] Error 2
make: *** [all] Error 2
user@user-BLRMIESPC-756:~/pcl/vlp_grabber/build$ 

Kindly provide me proper solution so that I can work further.

@JorgeVilchis

This comment has been minimized.

Show comment
Hide comment
@JorgeVilchis

JorgeVilchis Aug 9, 2017

I got a similar error, (meaning that the compiler indicated me that there are expressions only valid for c+11).
I just added this line to the CMakelists.txt file:

set(CMAKE_CXX_STANDARD 11)

it worked for me.

I got a similar error, (meaning that the compiler indicated me that there are expressions only valid for c+11).
I just added this line to the CMakelists.txt file:

set(CMAKE_CXX_STANDARD 11)

it worked for me.

@shaikhibrahim951

This comment has been minimized.

Show comment
Hide comment
@shaikhibrahim951

shaikhibrahim951 Aug 14, 2017

Hi JorgeVilchis,

Thanks for your help. Are you able to visualize point cloud using this code? Because when I am running this code and giving input saved pcap file, then one window with 3 axis getting opening and there is no point cloud data.
vlp

Can you help me regarding this isssue.

Hi JorgeVilchis,

Thanks for your help. Are you able to visualize point cloud using this code? Because when I am running this code and giving input saved pcap file, then one window with 3 axis getting opening and there is no point cloud data.
vlp

Can you help me regarding this isssue.

@shobhitkukreti

This comment has been minimized.

Show comment
Hide comment
@shobhitkukreti

shobhitkukreti Dec 4, 2017

Scroll up/down with your mouse center wheel

Scroll up/down with your mouse center wheel

@wangguojun2018

This comment has been minimized.

Show comment
Hide comment
@wangguojun2018

wangguojun2018 Mar 14, 2018

I build PCL with WITH_PCAP option. my visual studio is 2017. Then I build sample program successfully in https://gist.github.com/UnaNancyOwen/9f9459d3c10f7a6325ebebabda9865f7.But when I run the program, the program is always stopped.
image

I build PCL with WITH_PCAP option. my visual studio is 2017. Then I build sample program successfully in https://gist.github.com/UnaNancyOwen/9f9459d3c10f7a6325ebebabda9865f7.But when I run the program, the program is always stopped.
image

@pavankumarbn

This comment has been minimized.

Show comment
Hide comment
@pavankumarbn

pavankumarbn May 14, 2018

I am facing this issue in Ubuntu 14.04 with PCL 1.7. Any suggestions to fix this issue? As mentioned in the blog added 3 lines to cmakelist file but still facing the same error.
screenshot from 2018-05-14 16_57_10

I am facing this issue in Ubuntu 14.04 with PCL 1.7. Any suggestions to fix this issue? As mentioned in the blog added 3 lines to cmakelist file but still facing the same error.
screenshot from 2018-05-14 16_57_10

@amamphiswana

This comment has been minimized.

Show comment
Hide comment
@amamphiswana

amamphiswana Aug 13, 2018

@pavankumarbn : add set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") in your CMakelists.txt.

@pavankumarbn : add set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") in your CMakelists.txt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment