0
$\begingroup$

Rosanswers logo

Hi,

I am using hydro on ubuntu 12.04. I am trying to remove the point cloud outliers, but I can't get it right, can anyone help me take a look please? Thank you.

#include <ros/ros.h>
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>


ros::Publisher pub;

void 
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
  // Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud
  pcl::PointCloud<pcl::PointXYZ> cloud, cloud_filtered;
  pcl::fromROSMsg (*input, cloud);

  pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
  sor.setInputCloud (cloud);
  sor.setMeanK (50);
  sor.setStddevMulThresh (1.0);
  sor.filter (cloud_filtered);

  pcl::PCLPointCloud2 cloud_filtered2;
  pcl::toROSMsg (cloud_filtered, cloud_filtered2);

  // Publish the dataSize 
  pub.publish (cloud_filtered2);
}

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

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

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

  // Spin
  ros::spin ();
} 

Originally posted by chao on ROS Answers with karma: 153 on 2014-03-19

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Try this for your callback:

void 
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
    // Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud
    pcl::PointCloud<pcl::PointXYZ>::Ptr
        cloud(new pcl::PointCloud<pcl::PointXYZ> ()),
        cloud_filtered(new pcl::PointCloud<pcl::PointXYZ> ());
    pcl::fromROSMsg (*input, *cloud);

    pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
    sor.setInputCloud (cloud);
    sor.setMeanK (50);
    sor.setStddevMulThresh (1.0);
    sor.filter (*cloud_filtered);

    sensor_msgs::PointCloud2::Ptr
        cloud_filtered2(new sensor_msgs::PointCloud2 ());
    pcl::toROSMsg (*cloud_filtered, *cloud_filtered2);

    // Publish the dataSize 
    pub.publish (cloud_filtered2);
}

Does that do what you want?


Originally posted by jarvisschultz with karma: 9031 on 2014-03-19

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by chao on 2014-03-20:
yes, it works. Thanks alot :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.