Ask Your Question

How to construct the point cloud data from the depth data

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

lakshmen gravatar image

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

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

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

dornhege gravatar image

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

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


but i have written the code already and my supervisor wants to publish the message and populate it...
lakshmen gravatar imagelakshmen ( 2011-06-23 03:22:00 -0500 )edit
i have already done that... but i would like to use the openkinect(libfreenect) driver and run the pointcloud from that...
lakshmen gravatar imagelakshmen ( 2011-06-23 03:40:24 -0500 )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 imagedornhege ( 2011-06-23 03:40:25 -0500 )edit
u mean the sensor_msgs::PointCloud2?
lakshmen gravatar imagelakshmen ( 2011-06-23 03:42:31 -0500 )edit
I added a link to example code to my answer.
dornhege gravatar imagedornhege ( 2011-06-23 03:52:12 -0500 )edit
Why don't you read the text on the website? It is explained there.
dornhege gravatar imagedornhege ( 2011-06-23 04:49:52 -0500 )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 imagelakshmen ( 2011-06-26 14:08:09 -0500 )edit

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

lakshmen gravatar image

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

#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[0].name = "x";
 //msg->fields[1].name = "y";
 //msg->fields[2].name = "z";
 //msg->fields[3].name = "rgb";
 msg->is_dense = true;

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]);

 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


is this correct or wrong?
lakshmen gravatar imagelakshmen ( 2011-06-26 14:56:31 -0500 )edit
i know there are some mistakes.. it would be nice that some could point out to me....
lakshmen gravatar imagelakshmen ( 2011-06-26 19:04:07 -0500 )edit
shld i use sensor_msgs::PointCloud 2 or just pointCloud<pcl::PointXYZ> PointCloud?
lakshmen gravatar imagelakshmen ( 2011-06-26 20:24:35 -0500 )edit
No, you should use PointCloud as in the tutorial. That code works!
dornhege gravatar imagedornhege ( 2011-06-27 00:01:59 -0500 )edit
meaning to say that u dun use the sensor_msgs at all??
lakshmen gravatar imagelakshmen ( 2011-06-27 01:45:55 -0500 )edit
is the one u mean? i have edited the code...
lakshmen gravatar imagelakshmen ( 2011-06-27 02:04:40 -0500 )edit
Looks OK now. If you use exactly the code from the link I posted, that should do what you want.
dornhege gravatar imagedornhege ( 2011-06-27 20:08:25 -0500 )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 imagelakshmen ( 2011-07-03 20:08:20 -0500 )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


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

Seen: 8,623 times

Last updated: Jul 03 '11