Problem in implementing voxel grid filter on the point cloud using Kinect
I am working on ROS Indigo Igloo with platform Ubuntu 14.04. I have to implement voxel grid filter on the real time point cloud obtained by Kinect v1.1. I am following a tutorial http://aeswiki.datasys.swri.edu/rositraining/indigo/Exercises/4.5a from the tutorial series http://aeswiki.datasys.swri.edu/rositraining/indigo/Exercises/. The tutorial is written for working with a provided bag file in Exercise 4.4 but I want to implement it on the point cloud obtained by Kinect in the run time. Following is the node I am running.
include
include
include
include
include //hydro
// PCL specific includes
include //hydro
include "pcl_ros/transforms.h"
include
//#include
int main(int argc, char argv[]) { / * INITIALIZE ROS NODE */ ros::init(argc, argv, "perceptionnode"); ros::NodeHandle nh; ros::NodeHandle privnh_("~");
/* * SET UP PARAMETERS (COULD BE INPUT FROM LAUNCH FILE/TERMINAL) */ std::string cloudtopic, worldframe, cameraframe; worldframe="cameradepthopticalframe"; cameraframe="cameralink"; cloudtopic="camera/depth_registered/points";
/*
* SETUP PUBLISHERS
*/
ros::Publisher objectpub, clusterpub, posepub;
objectpub = nh.advertise
while (ros::ok()) { /* * LISTEN FOR POINTCLOUD */ std::string topic = nh.resolveName(cloudtopic); ROSINFOSTREAM("Cloud service called; waiting for a PointCloud2 on topic "<< topic); sensormsgs::PointCloud2::ConstPtr recentcloud = ros::topic::waitForMessage<sensormsgs::PointCloud2>(topic, nh);
/* * TRANSFORM POINTCLOUD FROM CAMERA FRAME TO WORLD FRAME */ tf::TransformListener listener; tf::StampedTransform stransform; try { listener.waitForTransform(worldframe, cameraframe, ros::Time::now(), ros::Duration(6.0)); listener.lookupTransform(worldframe, cameraframe, ros::Time(0), stransform); } catch (tf::TransformException ex) { ROSERROR("%s",ex.what()); } sensormsgs::PointCloud2 transformedcloud; pclros::transformPointCloud(worldframe, *recentcloud, transformed_cloud, listener);
/* * CONVERT POINTCLOUD ROS->PCL */ pcl::PointCloudpcl::PointXYZ cloud; pcl::fromROSMsg (transformed_cloud, cloud);
/* ======================================== * Fill Code: VOXEL GRID * ========================================/ pcl::PointCloudpcl::PointXYZ::Ptr cloudptr (new pcl::PointCloudpcl::PointXYZ (cloud)); pcl::PointCloudpcl::PointXYZ::Ptr cloudvoxelfiltered (new pcl::PointCloudpcl::PointXYZ ()); pcl::VoxelGridpcl::PointXYZ voxelfilter; voxelfilter.setInputCloud (cloudptr); voxelfilter.setLeafSize (float(0.005), float(0.005), float(0.005)); voxelfilter.filter (cloudvoxelfiltered);
ROSINFOSTREAM("Original cloud had " << cloudptr->size() << " points"); ROSINFOSTREAM("Downsampled cloud with " << cloudvoxel_filtered->size() << " points");
/* ======================================== * Fill Code: PASSTHROUGH FILTER(S) * ========================================*/ //filter in x
//filter in y
//filter in z
/* ======================================== * Fill Code: CROPBOX (OPTIONAL) * ========================================*/
/* ======================================== * Fill Code: PLANE SEGEMENTATION * ========================================*/
/* ======================================== * Fill Code: PUBLISH PLANE MARKER (OPTIONAL) * ========================================*/
/* ======================================== * Fill Code: EUCLIDEAN CLUSTER EXTRACTION (OPTIONAL/RECOMMENDED) * ========================================*/
/* ======================================== * Fill Code: STATISTICAL OUTLIER REMOVAL (OPTIONAL) * ========================================*/
/* ======================================== * CONVERT POINTCLOUD PCL->ROS * PUBLISH CLOUD * Fill Code: UPDATE AS NECESSARY * ========================================/ sensormsgs::PointCloud2::Ptr pc2cloud (new sensor_msgs::PointCloud2); pcl::toROSMsg(cloudvoxelfiltered, *pc2cloud); pc2cloud->header.frameid=worldframe; pc2cloud->header.stamp=ros::Time::now(); objectpub.publish(pc2_cloud);
/* ======================================== * Fill Code: PUBLISH OTHER MARKERS (OPTIONAL) * ========================================*/
/* ======================================== * BROADCAST TRANSFORM (OPTIONAL) * ========================================*/
/* ======================================== * Fill Code: POLYGONAL SEGMENTATION (OPTIONAL) * ========================================*/
} return 0; }
And I am getting the following error. In the rviz window when I subscribe to camera/depthregistered/points, it shows me what's infront of Kinect but when I subsribe to /objectcluster as told in the tutorial it shows nothing and terminal shows the same error.
[ERROR] [1468296058.980680825]: Lookup would require extrapolation into the past. Requested time 1468296052.937508136 but the earliest data is at time 1468296053.288398816, when looking up transform from frame [camerargbopticalframe] to frame [cameradepthopticalframe] Failed to find match for field 'x'. Failed to find match for field 'y'. Failed to find match for field 'z'. [ INFO] [1468296058.980761912]: Original cloud had 0 points [ INFO] [1468296058.980785701]: Downsampled cloud with 0 points
I have tried to fix it by replacing ros::Time::now by ros::Time(0) but nothing changes. It works absolutely fine with the provided bag file. Kindly let me know if anybody knows about this problem.
Asked by Hashir Shafi on 2016-07-11 23:51:33 UTC
Comments