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; | |
} |
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.
Scroll up/down with your mouse center wheel
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.
@pavankumarbn : add set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") in your CMakelists.txt.
@amamphiswana Thank you:)
is that possible that i can do point cloud stitching here? I try to use the point cloud to concat however, i cannot point the constptr cloud
to the new point cloud concated @UnaNancyOwen
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.
Can you help me regarding this isssue.
@shaikhibrahim951, I have the same problem with you. Did you find a solution to this issue? I've been troubled for several days. Plz help!!!! T T
I'm also having the same problem as @shaikhibrahim951 and @LiShuaixin. Adding set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") or set(CMAKE_CXX_STANDARD 11) did not help, nor trying with full path to .pcap file. Stream from lidar works perfectly.
My system is Ubuntu 16.04 and pcl 1.8.
I have compiled the codes under /build with cmake .. and make.
I got the same issue as @LiShuaixin. There is no pointcloud streaming from the pcap file. Can anyone help with this?
Hi, i'm very new to PCL and CMake. I'm trying to use this code to load the .pcap data by using VScode, however, the problem is ".../main.cpp:81: undefined reference to ‘pcl::VLPGrabber::VLPGrabber(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’ ". The line 81 is "grabber = boost::shared_ptrpcl::VLPGrabber( new pcl::VLPGrabber( pcap ) );" Can anyone help me? I'll appreciate it a lot!
`[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/elric/project/c++/vscodedemo/build --config Debug --target all -- -j 14
[build] [ 50%] Linking CXX executable project
[build] CMakeFiles/project.dir/main.cpp.o:in function ‘main’:
[build] /home/elric/project/c++/vscodedemo/main.cpp:81:undefined reference to ‘pcl::VLPGrabber::VLPGrabber(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’
[build] /home/elric/project/c++/vscodedemo/main.cpp:85:undefined reference to ‘pcl::VLPGrabber::VLPGrabber(boost::asio::ip::address const&, unsigned short)’
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [project] Error 1
[build] CMakeFiles/project.dir/build.make:374: recipe for target 'project' failed
[build] CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/project.dir/all' failed
[build] make[1]: *** [CMakeFiles/project.dir/all] Error 2
[build] make: *** [all] Error 2
[build] Makefile:83: recipe for target 'all' failed
[build] Build finished with exit code 2`
Hi, i'm very new to PCL and CMake. I'm trying to use this code to load the .pcap data by using VScode, however, the problem is ".../main.cpp:81: undefined reference to ‘pcl::VLPGrabber::VLPGrabber(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’ ". The line 81 is "grabber = boost::shared_ptrpcl::VLPGrabber( new pcl::VLPGrabber( pcap ) );" Can anyone help me? I'll appreciate it a lot!
`[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/elric/project/c++/vscodedemo/build --config Debug --target all -- -j 14
[build] [ 50%] Linking CXX executable project
[build] CMakeFiles/project.dir/main.cpp.o:in function ‘main’:
[build] /home/elric/project/c++/vscodedemo/main.cpp:81:undefined reference to ‘pcl::VLPGrabber::VLPGrabber(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’
[build] /home/elric/project/c++/vscodedemo/main.cpp:85:undefined reference to ‘pcl::VLPGrabber::VLPGrabber(boost::asio::ip::address const&, unsigned short)’
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [project] Error 1
[build] CMakeFiles/project.dir/build.make:374: recipe for target 'project' failed
[build] CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/project.dir/all' failed
[build] make[1]: *** [CMakeFiles/project.dir/all] Error 2
[build] make: *** [all] Error 2
[build] Makefile:83: recipe for target 'all' failed
[build] Build finished with exit code 2`
I solved this problem by myself. The reason caused this problem is that i download PCL1.7 before, and it linked to this version's LIB, therefore, it cann't find the VLPGrabber.h in PCL1.7. I uninstall the PCL1.7 and PCL1.8 and reinstall the PCL1.8 for Ubuntu, the program worked.
hi,
I got same issue
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
so please help me
thanks
kalai
I'm also having the same problem as @shaikhibrahim951 and @LiShuaixin. Adding set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") or set(CMAKE_CXX_STANDARD 11) did not help, nor trying with full path to .pcap file. Stream from lidar works perfectly.
hi,
got same issue, i directly given full path only
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
so please help me
thanks
kalai
My system is Ubuntu 16.04 and pcl 1.8.
I have compiled the codes under /build with cmake .. and make.
I got the same issue as @LiShuaixin. There is no pointcloud streaming from the pcap file. Can anyone help with this?
hi songwenhuang,
you can install libpcap with in the PCL folder .
open pcl folder using terminal and give below command
sudo apt-get install libpcap-dev
then open the your build folder then cmake and make after that it will work
thanks
kalai
Hello all,
When I am trying to retrieve the data from pcap files I am getting the segmentation fault (core dumped). Did anyone experienced the same error.
Any leads will be helpful
Hi, I am having below issue while reading .pcap file using vlpgrabber:
double free or corruption (out)
Aborted (core dumped)
any suggestion please?
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 ..
Second I did make
Kindly provide me proper solution so that I can work further.