Reading PointCloud2 in C++
How do you read a PointCloud2 in C++? I'm interested in getting the depth(z point). Maybe an equivalent of this: reading pointcloud2 in python.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
How do you read a PointCloud2 in C++? I'm interested in getting the depth(z point). Maybe an equivalent of this: reading pointcloud2 in python.
If you know what type of points you expect inside the PointCloud2, you can use the information from the pcl_ros wiki page for Subscribing to point clouds.
You seem already got an accepted answer but just for future reference,
You could use convertPointCloud2ToPointCloud
from sensor_msgs.
Once you input Pointcloud2 and got output as Pointcloud , then you can iterate through your points as such;
#include <sensor_msgs/PointCloud.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/point_cloud_conversion.h>
sensor_msgs::Pointcloud2 input_pointcloud;
sensor_msgs::Pointcloud out_pointcloud;
sensor_msgs::convertPointCloud2ToPointCloud(input_pointcloud, out_cloud);
for(int i = 0 ; i < out_cloud.points.size(); ++i){
geometry_msgs::Point32 point;
//Dooo something here
point.z = out_cloud.points[i].z;
}
And get xyz coordinates of all points
Asked: 2011-03-02 15:17:18 -0600
Seen: 13,892 times
Last updated: Feb 04 '20
Do I need to know any specific computer language or framework to use ROS?
Problem with sensor_msgs::Image::ConstPtr conversion to IplImage
Fast triangulation of unordered point clouds - adding new clouds
is ros client c++ code thread safe?
How to visualize colored pointclouds in rviz?
Do you have any advice for sending PointCloud2 over a wireless nework