0
$\begingroup$

Rosanswers logo

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..


Originally posted by lakshmen on ROS Answers with karma: 101 on 2011-06-21

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by dornhege with karma: 31395 on 2011-06-21

This answer was ACCEPTED on the original site

Post score: 5


Original comments

Comment by lakshmen on 2011-06-26:
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...

Comment by dornhege on 2011-06-23:
Why don't you read the text on the website? It is explained there.

Comment by dornhege on 2011-06-23:
I added a link to example code to my answer.

Comment by lakshmen on 2011-06-23:
u mean the sensor_msgs::PointCloud2?

Comment by dornhege on 2011-06-23:
just use the PointCloud class from the pcl as I said. It is very easy to fill the data in there and publish it.

Comment by lakshmen on 2011-06-23:
i have already done that... but i would like to use the openkinect(libfreenect) driver and run the pointcloud from that...

Comment by lakshmen on 2011-06-23:
but i have written the code already and my supervisor wants to publish the message and populate it...

$\endgroup$
0
$\begingroup$

Rosanswers logo

#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 ("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 ();  
}

}


Originally posted by lakshmen with karma: 101 on 2011-06-26

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by lakshmen on 2011-07-04:
okie thanks..but i still can't visualize it in Rviz. is it something to do with tf? i cant seem to change the fixed frame and target frame.

Comment by dornhege on 2011-07-04:
you should use PointCloud as in the tutorial. When you resize a vector to 640480, there are 640480 entries already, then you need to fill directly - push_back will add more additional entries.

Comment by lakshmen on 2011-07-03:
1 more thing i would like to ask, is it better to use pcl:pointcloud or sensor_msgs::PointCloud 2? which is better?or which would u suggest?

Comment by lakshmen on 2011-07-03:
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?

Comment by dornhege on 2011-06-27:
Looks OK now. If you use exactly the code from the link I posted, that should do what you want.

Comment by lakshmen on 2011-06-27:
is the one u mean? i have edited the code...

Comment by lakshmen on 2011-06-27:
meaning to say that u dun use the sensor_msgs at all??

Comment by dornhege on 2011-06-27:
No, you should use PointCloud as in the tutorial. That code works!

Comment by lakshmen on 2011-06-26:
shld i use sensor_msgs::PointCloud 2 or just pointCloudpcl::PointXYZ PointCloud?

Comment by lakshmen on 2011-06-26:
i know there are some mistakes.. it would be nice that some could point out to me....

Comment by lakshmen on 2011-06-26:
is this correct or wrong?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.