Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 171

Conversion from Point Cloud (PCL) to PointCloud2 (ROS) not showing result on RViz

$
0
0
Hello, I followed [this tutorial](http://wiki.ros.org/pcl/Tutorials) using `PCL` libraries to perform the conversion from point cloud into a `ROS` readable message `PointCloud2`. After compiling and running the example everything works, but I can't see anything on `RViz`. I have been trying to catch the error but no luck so far. Also [in this post](http://answers.ros.org/question/287133/ros-pcl-tutorials-problem/) they had the same problem but no solution was found. Also [this post](https://www.codesd.com/item/pcl-sampling-with-pcl-voxelgrid.html) was useful but no answer was provided. The code is the same as the tutorial, and I am providing it below for completeness: #include #include #include #include #include #include ros::Publisher pub; void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg) { // Container for original & filtered data pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; pcl::PCLPointCloud2ConstPtr cloudPtr(cloud); pcl::PCLPointCloud2 cloud_filtered; // Convert to PCL data type pcl_conversions::toPCL(*cloud_msg, *cloud); // Perform the actual filtering pcl::VoxelGrid sor; sor.setInputCloud (cloudPtr); sor.setLeafSize (0.1f, 0.1f, 0.1f); sor.filter (cloud_filtered); // Convert to ROS data type sensor_msgs::PointCloud2 output; pcl_conversions::moveFromPCL(cloud_filtered, output); // Publish the data pub.publish (output); } int main (int argc, char** argv) { // Initialize ROS ros::init (argc, argv, "pcl_tutorial_cloud"); ros::NodeHandle nh; // Create a ROS subscriber for the input point cloud ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb); // Create a ROS publisher for the output point cloud pub = nh.advertise ("output", 1); // Spin ros::spin (); } **Additional Source:** However, I didn't want to stop at that example only and tried to read from a `.pcd` file on my Desktop and try to publish it and showing `PointCloud2on` on `RViz`. And unfortunately this time too nothing was showing on `RViz`. Below the code that reads the file from my Desktop and try to publish and visualize point clouds on `RViz`: #include #include #include #include #include #include #include ros::Publisher pub; void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg) { // Container for original & filtered data pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; pcl::PCLPointCloud2ConstPtr cloudPtr(cloud); pcl::PCLPointCloud2 cloud_filtered; // Fill in the cloud data pcl::PCDReader reader; // Replace the path below with the path where you saved your file reader.read ("/home/to/Desktop/cloud_25.pcd", *cloud); std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height << " data points (" << pcl::getFieldsList (*cloud) << ")."; // Convert to PCL data type pcl_conversions::toPCL(*cloud_msg, *cloud); // Perform the actual filtering pcl::VoxelGrid sor; sor.setInputCloud (cloudPtr); sor.setLeafSize (0.1f, 0.1f, 0.1f); sor.filter (cloud_filtered); // Convert to ROS data type sensor_msgs::PointCloud2 output; pcl_conversions::moveFromPCL(cloud_filtered, output); // Publish the data pub.publish (output); } int main (int argc, char** argv) { // Initialize ROS ros::init (argc, argv, "pcl_tutorial_cloud"); ros::NodeHandle nh; // Create a ROS subscriber for the input point cloud ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb); // Create a ROS publisher for the output point cloud pub = nh.advertise ("output", 1); // Spin ros::spin (); } But when I was trying to run this second option I got the following from the compiler: `11:03:41: Starting /home/emanuele/catkin_ws/src/pcl_tutorial_cloud/src/test.cpp... 11:03:41: Failed to start program. Path or permissions wrong? 11:03:41: /home/emanuele/catkin_ws/src/pcl_tutorial_cloud/src/test.cpp exited with code -1 11:03:41: The process failed to start. Either the invoked program "/home/emanuele/catkin_ws/src/pcl_tutorial_cloud/src/test.cpp" is missing, or you may have insufficient permissions to invoke the program.`

Viewing all articles
Browse latest Browse all 171

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>