Can't visualize Pepper's PointCloud using PCL viewer
I have written a piece of code which subscribes to my Pepper Robot's depth_registered/points topic, converts the Sensor::msg object to pcl::PointCloud using pcl::fromROSMsg(), when I try to visualize the pcl point cloud via PCL viewer I get a green red black screen(refer this) I'm able to see the pointcloud on RViZ. I've tried converting the Sensor::msg PointCloud2 object to both pcl::PointCloudpcl::PointXYZRGB and pcl::PointCloudpcl::PointXYZ, both gives the same output.
Here's the snippet of code,
void callback(const sensor_msgs::PointCloud2ConstPtr &cloud) {
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudGround(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromROSMsg(*cloud, *cloudGround);
pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
viewer.showCloud (cloud);
while (!viewer.wasStopped ())
{
}
const std::string file_name = "pointcloud.pcd";
pcl::io::savePCDFileASCII (file_name, *cloudGround);
}
Also the depth coordinates from Pepper that I'm printing are very small in the order of 10^35. Is this expected? ROS Kinetic Ubuntu 16.04 Any help?
Asked by metalaman on 2018-02-16 06:24:56 UTC
Answers
What you're seeing is just the three axes zoomed in. Use the mouse wheel to scroll out and you'll see your scene. I felt pretty silly when I finally figured that out.
Asked by daniel-s-ingram on 2019-05-25 16:17:26 UTC
Comments
Some suggestions: save a pcd file, try it with pcl_viewer on the command line and share the file here. Print out the xyz of the first 10 points or so. Add a screenshot of what the proper cloud looks like in rviz. Supply your cloud viewer small artificial pointcloud instead of real data.
Asked by lucasw on 2018-02-16 13:58:10 UTC
Thanks for the suggestions, I tried saving to a pcd file, I'm able to see the point cloud on pcl_viewer, but it's inverted. Dunno why it didn't work programmatically. Also, I can't upload the screenshot, less karma. Thanks anyway.
Asked by metalaman on 2018-02-17 07:21:47 UTC
If you can put your code in the question text it may be possible to see what is wrong.
Asked by lucasw on 2018-02-17 22:04:22 UTC
Hi, I've added the code. Also I subscribed to depth/image_rect, which I think is the rectified depth image, and now all the depth values are normal.
Asked by metalaman on 2018-02-18 05:45:06 UTC
The viewer ought to be created outside the callback while the callback only updates the viewer with new points- but CloudViewer doesn't support multithreading http://pointclouds.org/documentation/tutorials/cloud_viewer.php - PCLVisualizer is supposed to. Though when I last tried it it crashed a lot
Asked by lucasw on 2018-02-18 10:14:14 UTC
It may not be your issue but it isn't a good design to have a ros message callback that comes to a halt for an interactive viewer rather than returning as quickly as possible.
Asked by lucasw on 2018-02-18 10:36:45 UTC
So, how to show point cloud with pcl? I create the viewer outside the callback but the it does not refresh. Do you mean the message uses multithreading method and the view will not work?
Asked by 七小丘人 on 2019-04-15 03:53:55 UTC
Crosslinking to #q321133
Asked by lucasw on 2019-04-15 09:38:05 UTC
I couldn't reconcile "CloudViewer class is NOT meant to be used in multi-threaded applications" with "PCLVisualizer is not suited to visualize data streams" so gave up on it https://github.com/lucasw/rqt_pcl_visualizer/issues/3
Asked by lucasw on 2019-04-15 09:56:13 UTC
Hey,
How are you using the pcl::visualization module? What's your header file and what have you included in your Cmakelist?
Asked by pravi on 2020-12-08 08:16:06 UTC