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

Revision history [back]

click to hide/show revision 1
initial version

Hi, Ok I guess you have missed the point that the Kinect has to be connected and openni_camera has to be started in order to grab image from the real world. Or you may have to simulate the same in Gazebo. Or you have to modify the code so that it does the processing on the standalone PCD file. 4.1 callback function is called only when the node subscribes to a cloud given by another node(Kinect). To download Kinect for ROS and make it work please follow the link.

Let me know if any issues. Hope this helps.

Karthik

Hi, Ok I guess you have missed the point that the Kinect has to be connected and openni_camera has to be started in order to grab image from the real world. Or you may have to simulate the same in Gazebo. Or you have to modify the code so that it does the processing on the standalone PCD file. 4.1 callback function is called only when the node subscribes to a cloud given by another node(Kinect). To download Kinect for ROS and make it work please follow the link.

Let me know if any issues. Hope this helps.

Karthik

input:=/narrow_stereo_texture/points2 is the input to your my_pcl_tutorial which here may not be the one given by the openni_camera node. Once you run the openni_camera, check for the topics it is publishing. I guess it should be /camera/rgb/points or /camera/depth/points so in that case your input becomes the topic it is publishing. Now as you run the my_pcl_tutorial, you should see some clouds coming. You may visualize the same in rviz as well. Let me know if it is working

Hi, Ok I guess you have missed the point that the Kinect has to be connected and openni_camera has to be started in order to grab image from the real world. Or you may have to simulate the same in Gazebo. Or you have to modify the code so that it does the processing on the standalone PCD file. 4.1 callback function is called only when the node subscribes to a cloud given by another node(Kinect). To download Kinect for ROS and make it work please follow the link.

Let me know if any issues. Hope this helps.

Karthik

input:=/narrow_stereo_texture/points2 is the input to your my_pcl_tutorial which here may not be the one given by the openni_camera node. Once you run the openni_camera, check for the topics it is publishing. I guess it should be /camera/rgb/points or /camera/depth/points so in that case your input becomes the topic it is publishing. Now as you run the my_pcl_tutorial, you should see some clouds coming. You may visualize the same in rviz as well. Let me know if it is working

David I am editing your code so as to use ros::fromROSMsg and ros::toROSMsg. The thing is that sensor_msgs::PointCloud2 type is not used in pcl to do the manipulations that you want to do. So you have to convert it in the code in the callback function to process the cloud and convert it back to rosmsg to publish it.

pcl::PointCloud<pcl::PointXYZRGB> PC;
pcl::PointCloud<pcl::PointXYZRGB> PC_filtered;
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud)
{
  pcl::fromROSMsg(*cloud, PC); //Now you can process this PC using the pcl functions 
  sensor_msgs::PointCloud2 cloud_filtered;

// Perform the actual filtering
   pcl::VoxelGrid< sensor_msgs::PointCloud2 > sor ;
   sor.setInputCloud (PC);
   sor.setLeafSize (0.01, 0.01, 0.01);
   sor.filter (PC_filtered);

  //Convert the pcl cloud back to rosmsg
  pcl::toROSMsg(PC_filtered, cloud_filtered);

  // Publish the data
  //You may have to set the header frame id of the cloud_filtered also
  pub.publish (cloud_filtered);
}

I may have missed out in the pointers n stuff about the functions in the above code which you may want to check before compiling.

Hi, Ok I guess you have missed the point that the Kinect has to be connected and openni_camera has to be started in order to grab image from the real world. Or you may have to simulate the same in Gazebo. Or you have to modify the code so that it does the processing on the standalone PCD file. 4.1 callback function is called only when the node subscribes to a cloud given by another node(Kinect). To download Kinect for ROS and make it work please follow the link.

Let me know if any issues. Hope this helps.

Karthik

input:=/narrow_stereo_texture/points2 is the input to your my_pcl_tutorial which here may not be the one given by the openni_camera node. Once you run the openni_camera, check for the topics it is publishing. I guess it should be /camera/rgb/points or /camera/depth/points so in that case your input becomes the topic it is publishing. Now as you run the my_pcl_tutorial, you should see some clouds coming. You may visualize the same in rviz as well. Let me know if it is working

David I am editing your code so as to use ros::fromROSMsg and ros::toROSMsg. The thing is that sensor_msgs::PointCloud2 type is not used in pcl to do the manipulations that you want to do. So you have to convert it in the code in the callback function to process the cloud and convert it back to rosmsg to publish it.

pcl::PointCloud<pcl::PointXYZRGB> PC;
pcl::PointCloud<pcl::PointXYZRGB> PC_filtered;
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud)
{
  pcl::fromROSMsg(*cloud, PC); //Now you can process this PC using the pcl functions 
  sensor_msgs::PointCloud2 cloud_filtered;

// Perform the actual filtering
   pcl::VoxelGrid< sensor_msgs::PointCloud2 > sor ;
   sor.setInputCloud (PC);
   sor.setLeafSize (0.01, 0.01, 0.01);
   sor.filter (PC_filtered);

  //Convert the pcl cloud back to rosmsg
  pcl::toROSMsg(PC_filtered, cloud_filtered);

  // Publish the data
  //You may have to set the header frame id of the cloud_filtered also
  pub.publish (cloud_filtered);
}

I may have missed out in the pointers n stuff about the functions in the above code which you may want to check before compiling.


For your convenience i have written this complete code for voxelization that you may run directly. Hope this helps you understand on how to code further for your project.

#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl_ros/point_cloud.h>
#include <ros/ros.h>
#include <boost/foreach.hpp>
#include <sensor_msgs/PointCloud2.h>
#include <pcl/io/pcd_io.h>

using namespace std;
ros::Publisher pub;
typedef pcl::PointXYZRGB rgbpoint;
typedef pcl::PointCloud<pcl::PointXYZRGB> cloudrgb;
typedef cloudrgb::Ptr cloudrgbptr;
void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud)
{
  cloudrgbptr PC (new cloudrgb());
  cloudrgbptr PC_filtered (new cloudrgb());
  pcl::fromROSMsg(*cloud, *PC); //Now you can process this PC using the pcl functions 
  sensor_msgs::PointCloud2 cloud_filtered;


// Perform the actual filtering
   pcl::VoxelGrid<pcl::PointXYZRGB> sor ;
   sor.setInputCloud (PC);
   sor.setLeafSize (0.01, 0.01, 0.01);
   sor.filter (*PC_filtered);

  //Convert the pcl cloud back to rosmsg
  pcl::toROSMsg(*PC_filtered, cloud_filtered);
  //Set the header of the cloud
  cloud_filtered.header.frame_id = cloud->header.frame_id;
  // Publish the data
  //You may have to set the header frame id of the cloud_filtered also
  pub.publish (cloud_filtered);
}
int main(int argc, char ** argv)
{
    ros::init(argc, argv, "test_pcl_ros");
    ros::NodeHandle nh;
    ros::Subscriber sub = nh.subscribe("camera/rgb/points", 1, cloud_cb);
    pub = nh.advertise<sensor_msgs::PointCloud2> ("/camera/rgb/david", 1);
    ros::spin();
}

Thanks Karthik