PCL Tutorial doesn't show anything
Hi,
I was following the tutorial of PCL with ROS here, the 4.1 program, I got everything compiled, and I run my program, but I get this error:
home/david/ros_workspace/another_mypcltut/src/run_test.cpp:25:25: error: no matching function for call to ‘pcl::VoxelGrid<sensor_msgs::pointcloud2_<std::allocator<void> > >::setInputCloud(pcl::PointCloud<pcl::pointxyzrgb>&)’
This is the code I've used:
//pcl::PointCloud< pcl::PointXYZRGB> PC; //pcl::PointCloud< pcl::PointXYZRGB> PC_filtered; pcl::PointCloud< pcl::PointXYZ> PC; pcl::PointCloud< pcl::PointXYZ> PC_filtered;
void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud) { pcl::fromROSMsg(*cloud, PC); //Now you can process this PC using the pcl functions sensor_msgs::PointCloud2 cloud_filtered; // Perform the actual filtering pcl::VoxelGrid< sensor_msgs::PointCloud2> sor ; sor.setInputCloud (PC); //sor.setInputCloud (PC); sor.setLeafSize (0.01, 0.01, 0.01); sor.filter (PC_filtered);
//Convert the pcl cloud back to rosmsg try{ pcl::toROSMsg(*PC_filtered, cloud_filtered);} catch(std::runtime_error e){ ROS_ERROR_STREAM("Error in converting cloud to image message: "<< e.what());}
// Publish the data pub.publish (cloud_filtered); }
Though, browsing for some programs that does compile, to have an idea, I found this program which it does compile (it's not related to the first program, it's a different I have found):
void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input) { // Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud pcl::PointCloud< pcl::PointXYZ> cloud; pcl::fromROSMsg (*input, cloud); pcl::ModelCoefficients coefficients; pcl::PointIndices inliers; // Create the segmentation object pcl::SACSegmentation< pcl::PointXYZ> seg; // Optional seg.setOptimizeCoefficients (true); // Mandatory seg.setModelType (pcl::SACMODEL_PLANE); seg.setMethodType (pcl::SAC_RANSAC); seg.setDistanceThreshold (0.01);
seg.setInputCloud (cloud.makeShared ()); seg.segment (inliers, coefficients);
// Publish the model coefficients pub.publish (coefficients); }
The part I found interesting was this line:
seg.setInputCloud (cloud.makeShared ())
In which both functions:
setInputCloud (const PointCloudConstPtr &cloud)
Have as argument a ptr, and the 'makeShared()' function returns a shared pointer to the copy of the cloud. However this only work in the second program, when I run with the function mentioned in the first program, I get this error:
/home/david/ros_workspace/another_mypcltut/src/run_test.cpp:24:39: error: no matching function for call to ‘pcl::VoxelGrid<sensor_msgs::pointcloud2_<std::allocator<void> > >::setInputCloud(pcl::PointCloud<pcl::pointxyzrgb>::Ptr)’
Why is that happenning? :/ Thanks
P.S.1: Features of my software: * Ubuntu 11.04 * ROS Electric * PCL 1.5
P.S.2: Does this has anything to do with the fact I should have installed the PCL with ROS package (ros-unstable-perception-pcl) instead the one I have (ros-electric-perception-pcl)?? I have read a forum where a person asks for some errors while compiling using VoxelGrid (different than mines) and they suggested that they should have that one (dont know if that actually fixed the problem)
you have to include the #include <pcl/filters/voxel_grid.h> to work with Voxels. You may try now the same on sensor_msgs datatype of your code and see if it compiles.
thanks for organizing your question after my request :)
please check my updated answer with code for you to test with