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

PCL Tutorial doesn't show anything

asked 2012-04-24 18:58:24 -0500

DavidLavy gravatar image

updated 2012-05-02 04:12:20 -0500

Hi,

I was following the tutorial of PCL with ROS here, the 4.1 program, I got everything compiled, and I run my program, but I get this error:

home/david/ros_workspace/another_mypcltut/src/run_test.cpp:25:25: error: no matching function for call to ‘pcl::VoxelGrid<sensor_msgs::pointcloud2_<std::allocator<void> > >::setInputCloud(pcl::PointCloud<pcl::pointxyzrgb>&)’

This is the code I've used:

//pcl::PointCloud< pcl::PointXYZRGB> PC;
//pcl::PointCloud< pcl::PointXYZRGB> PC_filtered;
pcl::PointCloud< pcl::PointXYZ> PC;
pcl::PointCloud< pcl::PointXYZ> PC_filtered;

void 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.setInputCloud (PC); sor.setLeafSize (0.01, 0.01, 0.01); sor.filter (PC_filtered);

//Convert the pcl cloud back to rosmsg try{ pcl::toROSMsg(*PC_filtered, cloud_filtered);} catch(std::runtime_error e){ ROS_ERROR_STREAM("Error in converting cloud to image message: "<< e.what());}

// Publish the data pub.publish (cloud_filtered); }

Though, browsing for some programs that does compile, to have an idea, I found this program which it does compile (it's not related to the first program, it's a different I have found):

 void 
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
  // Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud
  pcl::PointCloud< pcl::PointXYZ> cloud;
  pcl::fromROSMsg (*input, cloud);
  pcl::ModelCoefficients coefficients;
  pcl::PointIndices inliers;
  // Create the segmentation object
  pcl::SACSegmentation< pcl::PointXYZ> seg;
  // Optional
  seg.setOptimizeCoefficients (true);
  // Mandatory
  seg.setModelType (pcl::SACMODEL_PLANE);
  seg.setMethodType (pcl::SAC_RANSAC);
  seg.setDistanceThreshold (0.01);

seg.setInputCloud (cloud.makeShared ()); seg.segment (inliers, coefficients);
// Publish the model coefficients pub.publish (coefficients); }

The part I found interesting was this line:

 seg.setInputCloud (cloud.makeShared ()) 

In which both functions:

setInputCloud (const PointCloudConstPtr &cloud)

Have as argument a ptr, and the 'makeShared()' function returns a shared pointer to the copy of the cloud. However this only work in the second program, when I run with the function mentioned in the first program, I get this error:

/home/david/ros_workspace/another_mypcltut/src/run_test.cpp:24:39: error: no matching function for call to ‘pcl::VoxelGrid<sensor_msgs::pointcloud2_<std::allocator<void> > >::setInputCloud(pcl::PointCloud<pcl::pointxyzrgb>::Ptr)’

Why is that happenning? :/ Thanks

P.S.1: Features of my software: * Ubuntu 11.04 * ROS Electric * PCL 1.5

P.S.2: Does this has anything to do with the fact I should have installed the PCL with ROS package (ros-unstable-perception-pcl) instead the one I have (ros-electric-perception-pcl)?? I have read a forum where a person asks for some errors while compiling using VoxelGrid (different than mines) and they suggested that they should have that one (dont know if that actually fixed the problem)

edit retag flag offensive close merge delete

Comments

you have to include the #include <pcl/filters/voxel_grid.h> to work with Voxels. You may try now the same on sensor_msgs datatype of your code and see if it compiles.

karthik gravatar image karthik  ( 2012-05-02 05:04:29 -0500 )edit

thanks for organizing your question after my request :)

karthik gravatar image karthik  ( 2012-05-02 05:04:52 -0500 )edit

please check my updated answer with code for you to test with

karthik gravatar image karthik  ( 2012-05-02 07:21:27 -0500 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2012-04-24 22:31:18 -0500

karthik gravatar image

updated 2012-05-02 05:03:00 -0500

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 ...
(more)
edit flag offensive delete link more

Comments

Thanks Karthik, Your example helped me solve a problem.

AndresCH gravatar image AndresCH  ( 2013-09-12 14:56:53 -0500 )edit

@karthik have you used the pcl17? and manage to make it work with ROS? if sodo you now ow tu create a publisher in the pcl code and make it work?

ctguell gravatar image ctguell  ( 2013-10-08 08:51:47 -0500 )edit

I was able to get it work on my ROS electric successfully and also helped someone do the same on Fuerte. But I am still working on making it work for the Groovy.

karthik gravatar image karthik  ( 2013-10-15 05:53:41 -0500 )edit
0

answered 2012-05-02 19:26:27 -0500

DavidLavy gravatar image

Mr. Karthik, The code it did compile, and publish the output msg as a PointCloud2 type (thank you very much for this!), though while I'm trying to visualize the point cloud using:

$ rosrun image_view image_view image:=/camera/rgb/david_img

(Previously running this line:

$ rosrun pcl_ros convert_pointcloud_to_image input:=/camera/rgb/david output:=/camera/rgb/david_img)

I get this msg:

OpenCV Error: Bad argument (Unknown array type) in cvarrToMat, file /tmp/buildd/libopencv-2.3.1+svn6514+branch23/modules/core/src/matrix.cpp, line 646 terminate called after throwing an instance of 'cv::Exception' what(): /tmp/buildd/libopencv-2.3.1+svn6514+branch23/modules/core/src/matrix.cpp:646: error: (-5) Unknown array type in function cvarrToMat

Why is not able to visualize this img?

Thanks!

edit flag offensive delete link more

Comments

I'm not sure if this should be a different question, or if is still considered related to the topic. Let me know please, thank you.

DavidLavy gravatar image DavidLavy  ( 2012-05-02 19:27:45 -0500 )edit

I hope the question here is answered. This is a different question. You can visualize the pointclouds in rviz. I am not sure about the pointcloud to image conversion. So please post this as a new question so that someone can answer it for you.

karthik gravatar image karthik  ( 2012-05-02 23:46:33 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2012-04-24 18:58:24 -0500

Seen: 7,042 times

Last updated: May 02 '12