Ask Your Question

Reading PointCloud2 in C++

asked 2011-03-02 15:17:18 -0600

Homer Manalo gravatar image

updated 2014-01-28 17:09:15 -0600

ngrennan gravatar image

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.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-03-02 15:20:42 -0600

Eric Perko gravatar image

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.

edit flag offensive delete link more


Is the origin(0.0, 0.0) of points x and y at the center of frame? I'm seeing a negative y point here.
Homer Manalo gravatar image Homer Manalo  ( 2011-03-02 18:40:01 -0600 )edit
That depends on whoever sends the pointcloud and what frame the data is in. For sensors the origin is usually (0,0,0). A negative y is also not unexpected. It could mean a point right or below the sensor (depending on the coordinate system)
dornhege gravatar image dornhege  ( 2011-03-02 21:58:07 -0600 )edit
I'm just using the pointcloud from stereo_image_proc. Where is the origin here? (top-left corner? top-right corner? center of the image?)
Homer Manalo gravatar image Homer Manalo  ( 2011-03-03 00:09:48 -0600 )edit
What is the reported frame_id in the PointCloud2 you are reading?
Eric Perko gravatar image Eric Perko  ( 2011-03-03 04:27:19 -0600 )edit
The frame_id is [camera]. I actually have a warning message on the rviz console window saying [camera] is not a fully qualified frame_id (resolved locally to [/camera]). I have not setup any tf here.
Homer Manalo gravatar image Homer Manalo  ( 2011-03-03 11:43:41 -0600 )edit
That warning isn't a big deal. The question I had was what sort of reference frame the PointCloud was using. According to the diagram and docs at , /camera ought to be the frame of the left camera in the pair.
Eric Perko gravatar image Eric Perko  ( 2011-03-03 11:54:40 -0600 )edit
Note that that is an optical frame, with Z pointing along the camera's viewing axis, not a standard body frame. In that situation, the camera frame should be specified with an _optical suffix, as noted in REP 105: .
Eric Perko gravatar image Eric Perko  ( 2011-03-03 11:55:48 -0600 )edit
For some reason, I did not notice that. Thanks.
Homer Manalo gravatar image Homer Manalo  ( 2011-03-03 13:03:51 -0600 )edit

answered 2018-09-07 01:33:34 -0600

Fetullah Atas gravatar image

updated 2020-02-04 02:51:59 -0600

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-03-02 15:17:18 -0600

Seen: 9,203 times

Last updated: Feb 04 '20