How to extract the world co-ordinates from a PCL.
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??