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::PointCloud<pcl::pointxyzrgb> and pcl::PointCloud<pcl::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?
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.
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.
If you can put your code in the question text it may be possible to see what is wrong.
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.
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/... - PCLVisualizer is supposed to. Though when I last tried it it crashed a lot
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.
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?
Crosslinking to #q321133