Ask Your Question

How to extract the world co-ordinates from a PCL.

asked 2014-09-11 10:26:18 -0600

m1ckey gravatar image

updated 2014-09-16 11:00:18 -0600


I am currently trying to extract the world co-ordinates from a pointcloud reconstructed scene. I am currently using ROS-Hydro.

I have followed these two as my reference.

I am subscribing to the pointcloud message generated by the proc stereo_img_proc.

My code is something like this.

#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl/conversions.h> 
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <opencv/highgui.h>
#include <cv_bridge/cv_bridge.h>
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <boost/foreach.hpp>
#include <pcl/PCLPointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>

void cloud_cb (const sensor_msgs::PointCloud2 pc)

pcl::PCLPointCloud2 pcl_pc;
pcl_conversions::toPCL(pc, pcl_pc);
pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::fromPCLPointCloud2(pcl_pc, cloud);
for(int i=0;i<cloud.height;i++)  
    for(int j=0; j<cloud.height;j++)    
         BOOST_FOREACH (const pcl::PointXYZ& pt, cloud.points);


I want to have the depth value for every pixel and then publish it in form of a sensor_msgs::Image message. Please guide me.


I have made some modifications.

for(int j=0; j<cloud.points.size();j++)    
    float x = cloud.points[j].x;
    float y = cloud.points[j].y;
    float z = cloud.points[j].z;


where x,y,z are the world co-ordinates as extracted from cloud. Will this work??

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-09-14 09:06:13 -0600

paulbovbel gravatar image

updated 2014-09-14 09:14:26 -0600

The 'world coordinates' of a pointcloud are represented in the transform data. If your pointcloud is in the sensor frame, and you have a tf transform (link) available to a map or world frame, you can use the tf library to transform the pointcloud into the desired frame, which will transform the positions of the points in the pointcloud.

The image you're talking about sounds like a projection of the pointcloud down to a 2D plane, which you can do by iterating over every point in the cloud (which you're already doing) and applying some linear algebra (look into the Eigen library). To actually build the image you'll probably find OpenCV and this conversion useful, however you could build the sensor_msgs/Image directly.

EDIT: Found this projection API in PCL as well which should make it easier.

edit flag offensive delete link more



Actually my point is I want to extract the depth or Z coordinate from a PCL and in place of the intensity value of the pixel I want to replace the same with the Z co-ordinate value.

m1ckey gravatar image m1ckey  ( 2014-09-16 05:37:32 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2014-09-11 10:26:18 -0600

Seen: 3,963 times

Last updated: Sep 16 '14