ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

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

Hi,

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. http://answers.ros.org/question/98011... http://wiki.ros.org/pcl_ros

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.

Edit:

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
1

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

Comments

Hi,

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

Question Tools

1 follower

Stats

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

Seen: 4,551 times

Last updated: Sep 16 '14