Unable to subscribe to Openni_launch - dataset doesn't have x-y-z coordinates
Hello all,
I am trying to write a simple program that subscribes to openni_launch's /camera/depth_registered/points topic. The code I have written publishes on another topic some extracted planes. Essentially I would like my program to take data from the kinect, extract the planes, and then publish these.
So far, I have used a .pcd file to get my program to publish the planes but when I try to implement this with real-time data I am unable to correctly subscribe to the openni node. What I tried to do was use the simple subscription program on the ROS.org website and combine this with my publisher/indice-extractor.
My code complies fine, but then when I try to run I obtain this output:
PointCloud before filtering: 0 data points. [pcl::VoxelGrid::applyFilter] Input dataset doesn't have x-y-z coordinates! Failed to find a field named: 'x'. Cannot convert message to PCL type. terminate called after throwing an instance of 'pcl::InvalidConversionException' what(): Failed to find a field named: 'x'. Cannot convert message to PCL type.
From this I understand that my PointCloud cloud_blob contains no data. But when I output in the callback function there is data.
Here is the top of my code up to the point where it crashes:
typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloud;
void callback(const PointCloud::ConstPtr& cloud_blob)
{
printf ("Cloud: width = %d, height = %d\n", cloud_blob->width, cloud_blob->height);
BOOST_FOREACH (const pcl::PointXYZRGB& pt, cloud_blob->points)
printf ("\t(%f, %f, %f)\n", pt.x, pt.y, pt.z);
}
int
main (int argc, char** argv)
{
// INITIALIZE ROS
ros::init (argc, argv, "SUB_IND_PUB");
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<PointCloud> ("pubIndices", 1);
sensor_msgs::PointCloud2::Ptr cloud_blob (new sensor_msgs::PointCloud2);
sensor_msgs::PointCloud2::Ptr cloud_filtered_blob (new sensor_msgs::PointCloud2);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_p (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_f (new pcl::PointCloud<pcl::PointXYZ>);
ros::Subscriber sub = nh.subscribe<PointCloud>("/camera/depth_registered/points", 1, callback);
ros::spinOnce ();
std::cerr << "PointCloud before filtering: " << cloud_blob->width * cloud_blob->height << " data points. " << std::endl;
// Create the filtering object: downsample the dataset using a leaf size of 1cm
pcl::VoxelGrid<sensor_msgs::PointCloud2> sor;
sor.setInputCloud (cloud_blob);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered_blob);
Thank you for any help or enlightenment!
Cheers, Martin