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

How to construct the point cloud data from the depth data

asked 2011-06-21 15:35:02 -0600

lakshmen gravatar image

updated 2016-10-24 09:09:57 -0600

ngrennan gravatar image

I have already acheived the depth data from the Kinect using the openkinect driver. I have already got the data for the x, y and z of the point cloud.Now, I need to plot point cloud data and would like to visualize it in rviz.How do i go about doing it?

Any help would be appreciated..

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
5

answered 2011-06-21 21:45:12 -0600

dornhege gravatar image

updated 2011-06-23 03:48:31 -0600

Publish a sensor_msgs::PointCloud2. The easiest way would be to create a PointCloud object from the pcl and publish that directly. Section 3.1 in pcl_ros has a code example.

It is even easier to run the openni_camera node that does that for you.

edit flag offensive delete link more

Comments

but i have written the code already and my supervisor wants to publish the message and populate it...
lakshmen gravatar image lakshmen  ( 2011-06-23 03:22:00 -0600 )edit
i have already done that... but i would like to use the openkinect(libfreenect) driver and run the pointcloud from that...
lakshmen gravatar image lakshmen  ( 2011-06-23 03:40:24 -0600 )edit
just use the PointCloud class from the pcl as I said. It is very easy to fill the data in there and publish it.
dornhege gravatar image dornhege  ( 2011-06-23 03:40:25 -0600 )edit
u mean the sensor_msgs::PointCloud2?
lakshmen gravatar image lakshmen  ( 2011-06-23 03:42:31 -0600 )edit
I added a link to example code to my answer.
dornhege gravatar image dornhege  ( 2011-06-23 03:52:12 -0600 )edit
Why don't you read the text on the website? It is explained there.
dornhege gravatar image dornhege  ( 2011-06-23 04:49:52 -0600 )edit
hi.. sorry was busy over the weekend... wasnt able to use the net...just got back to work...i will write the code here... if it is wrong, can u please help me... thanks.. really sorry to disturb you...
lakshmen gravatar image lakshmen  ( 2011-06-26 14:08:09 -0600 )edit
1

answered 2011-06-26 14:55:48 -0600

lakshmen gravatar image

updated 2011-07-03 20:05:15 -0600

#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>

typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;

int main(int argc, char** argv)

{ ros::init (argc, argv, "pub_pcl"); ros::NodeHandle nh; ros::Publisher pub = nh.advertise<pointcloud> ("point2", 1);

 PointCloud::Ptr msg (new PointCloud);
 msg->header.frame_id = "some_tf_frame";
 msg->height = 480;
 msg->width = 640;
 //msg->fields.resize(4);
 //msg->fields[0].name = "x";
 //msg->fields[1].name = "y";
 //msg->fields[2].name = "z";
 //msg->fields[3].name = "rgb";
 msg->is_dense = true;
 msg->points.resize(640*480);

for( int v=0,i=0;v<480;v++)
{
  for ( int u = 0; u<640;u++,i++)
   {
    pcl::PointXYZ result;
    result.x = (u-cx)*(RawDepthtoMeters(depth[i]) + minDistance*scaleFactor*(cx/cy);
    result.y = (v-cy)*(RawDepthtoMeters(depth[i]) + minDistance*scaleFactor;
    result.z = RawDepethtoMeters(depth[i]);
    msg->points.push.back(result);
   }
}

 ros::Rate loop_rate(4);  
 while (nh.ok())
{   
 msg->header.stamp = ros::Time::now ();
 pub.publish (msg); 
 ros::spinOnce ();
 loop_rate.sleep ();  
}

}

edit flag offensive delete link more

Comments

is this correct or wrong?
lakshmen gravatar image lakshmen  ( 2011-06-26 14:56:31 -0600 )edit
i know there are some mistakes.. it would be nice that some could point out to me....
lakshmen gravatar image lakshmen  ( 2011-06-26 19:04:07 -0600 )edit
shld i use sensor_msgs::PointCloud 2 or just pointCloud<pcl::PointXYZ> PointCloud?
lakshmen gravatar image lakshmen  ( 2011-06-26 20:24:35 -0600 )edit
No, you should use PointCloud as in the tutorial. That code works!
dornhege gravatar image dornhege  ( 2011-06-27 00:01:59 -0600 )edit
meaning to say that u dun use the sensor_msgs at all??
lakshmen gravatar image lakshmen  ( 2011-06-27 01:45:55 -0600 )edit
is the one u mean? i have edited the code...
lakshmen gravatar image lakshmen  ( 2011-06-27 02:04:40 -0600 )edit
Looks OK now. If you use exactly the code from the link I posted, that should do what you want.
dornhege gravatar image dornhege  ( 2011-06-27 20:08:25 -0600 )edit
hey dornhege, i have edited the code aboveand i changed it according to my need, but i cant get the point cloud. My purpose is to publish the point cloud data. what should i do? any suggestions?
lakshmen gravatar image lakshmen  ( 2011-07-03 20:08:20 -0600 )edit

Question Tools

Stats

Asked: 2011-06-21 15:35:02 -0600

Seen: 9,474 times

Last updated: Jul 03 '11