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

passthrough filter error

asked 2014-07-09 07:48:28 -0500

hamdi gravatar image

updated 2014-07-09 07:49:33 -0500

hi, I want to do obstacle avoidance using two filter but I get the following error:

/home/esetron/catkin_ws/src/sabir/src/sabir_node.cpp: In function ‘void cloud_cb(const PCLPointCloud2ConstPtr&)’:
/home/esetron/catkin_ws/src/sabir/src/sabir_node.cpp:25:53: error: no matching function for call to ‘pcl::PassThrough<pcl::PCLPointCloud2>::setInputCloud(pcl::PCLPointCloud2&)’
/home/esetron/catkin_ws/src/sabir/src/sabir_node.cpp:25:53: note: candidate is:
/usr/include/pcl-1.7/pcl/pcl_base.h:204:7: note: void pcl::PCLBase<pcl::PCLPointCloud2>::setInputCloud(const PCLPointCloud2ConstPtr&)
/usr/include/pcl-1.7/pcl/pcl_base.h:204:7: note:   no known conversion for argument 1 from ‘pcl::PCLPointCloud2’ to ‘const PCLPointCloud2ConstPtr& {aka const boost::shared_ptr<const pcl::PCLPointCloud2>&}’
make[2]: *** [sabir/CMakeFiles/sabir_node.dir/src/sabir_node.cpp.o] Error 1
make[1]: *** [sabir/CMakeFiles/sabir_node.dir/all] Error 2
make: *** [all] Error 2

Actually, when I added to code line "pass_through_filter.setInputCloud(cloud_filtered);", I am getting the current error. why I am getting this error?

thanks

my code:

#include <ros/ros.h>
    #include <iostream>
    // PCL specific includes
     #include <pcl_conversions/pcl_conversions.h>
     #include <sensor_msgs/PointCloud2.h>
    #include <pcl/point_cloud.h>
    #include <pcl/point_types.h>
    #include <pcl/filters/passthrough.h>
    #include <pcl/filters/voxel_grid.h>

    ros::Publisher pub;

    void cloud_cb(const pcl::PCLPointCloud2ConstPtr& input)
    {

      pcl::PCLPointCloud2 cloud_filtered;
      pcl::VoxelGrid<pcl::PCLPointCloud2> sor;

    sor.setInputCloud(input);
    sor.setLeafSize(0.01, 0.01, 0.01);
    sor.filter(cloud_filtered);

    // Create the appropriate pass-through filter
        pcl::PassThrough<pcl::PCLPointCloud2> pass_through_filter;
        pass_through_filter.setInputCloud(cloud_filtered);

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

    int main (int argc, char** argv){
    // Initialize ROS
    ros::init (argc, argv, "sabir");
    ros::NodeHandle nh;

     // Create a ROS subscriber for the input point cloud
    ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb);

    // Create a ROS publisher for the output point cloud
    pub = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);

    // Spin
    ros::spin ();
    }
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
3

answered 2014-07-10 09:18:36 -0500

hamdi gravatar image

Marti thanks for answer.

the following code is correct code for pass through filter and voxel grid filter in Ros Hydro:

#include <ros/ros.h>
#include <iostream>
// PCL specific includes
 #include <pcl_conversions/pcl_conversions.h>
 #include <sensor_msgs/PointCloud2.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/voxel_grid.h>

ros::Publisher pub;

void cloud_cb(const pcl::PCLPointCloud2ConstPtr& input)
{

  //pcl::PCLPointCloud2 cloud_filtered;
  pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2);
  pcl::PCLPointCloud2::Ptr cloud_pass(new pcl::PCLPointCloud2);
  pcl::VoxelGrid<pcl::PCLPointCloud2> sor;

    pcl::PassThrough<pcl::PCLPointCloud2> pass_through_filter;

    //pass through filter
    pass_through_filter.setInputCloud (input);
    pass_through_filter.filter (*cloud_pass);

    //voxel grid filter
    sor.setInputCloud(cloud_pass);
    sor.setLeafSize(0.05, 0.05, 0.05);
    sor.filter(*cloud_filtered);


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

int main (int argc, char** argv){
// Initialize ROS
ros::init (argc, argv, "sabir");
ros::NodeHandle nh;

 // Create a ROS subscriber for the input point cloud
ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb);

// Create a ROS publisher for the output point cloud
pub = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);

// Spin
ros::spin ();
}
edit flag offensive delete link more

Comments

Great :) Please mark it as correct :) Thanks!

martimorta gravatar image martimorta  ( 2014-07-10 09:44:27 -0500 )edit

I meant this one (yours) which has the correct code

martimorta gravatar image martimorta  ( 2014-07-10 10:07:20 -0500 )edit

I tried but I am taking this error: "25 points required to accept or unaccept your own answer"

hamdi gravatar image hamdi  ( 2014-07-10 10:31:07 -0500 )edit

I think I will be able to fix it tomorrow, anyway I gave an "up" to your question so you have +10 points :)

martimorta gravatar image martimorta  ( 2014-07-10 10:48:59 -0500 )edit

finally happened ;)

hamdi gravatar image hamdi  ( 2014-07-11 02:14:37 -0500 )edit
1

answered 2014-07-09 08:00:41 -0500

I think cloud_filtered should be pointer (not 100% sure though):

pcl::PCLPointCloud2::Ptr cloud_filtered
edit flag offensive delete link more

Comments

Marti, I tried but it did not or I could not

hamdi gravatar image hamdi  ( 2014-07-09 09:53:54 -0500 )edit

Question Tools

4 followers

Stats

Asked: 2014-07-09 07:48:28 -0500

Seen: 3,098 times

Last updated: Jul 10 '14