Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

PCL-ROS run time error while doing plane segmentation.

Hello everyone, I am trying to do plane segmentation using PCL and ROS. I am using the sensor Asus xtion pro live. I was able to launch openni_kinect and got the sensor pumping out necessary coordinates.

Here is my program:

ros::Publisher pub;
sensor_msgs::PointCloud2::Ptr downsampled,output;   



void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
pcl::PointCloud<pcl::pointxyz>::Ptr output_p(new pcl::PointCloud<pcl::pointxyz>);
pcl::PointCloud<pcl::pointxyz>::Ptr downsampled_XYZ(new pcl::PointCloud<pcl::pointxyz>);
 output_p->width=10;   
 output_p->height=10;
downsampled_XYZ->width=10;
downsampled_XYZ->height=10;

pcl::VoxelGrid<sensor_msgs::pointcloud2> sor;
sor.setInputCloud (input);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*downsampled);
// Change from type sensor_msgs::PointCloud2 to pcl::PointXYZ
pcl::fromROSMsg (*downsampled, *downsampled_XYZ);
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
// 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.setMaxIterations (1000);
      seg.setDistanceThreshold (0.01);

      // Create the filtering object
      pcl::ExtractIndices<pcl::pointxyz> extract;

      // Segment the largest planar component from the cloud
      seg.setInputCloud (downsampled_XYZ);
      seg.segment (*inliers, *coefficients);
      if (inliers->indices.size () == 0)
          {
              std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;
              }

      // Extract the inliers
      extract.setInputCloud (downsampled_XYZ);
      extract.setIndices (inliers);
      extract.setNegative (false);
      extract.filter (*output_p);
      std::cerr << "PointCloud representing the planar component: " << output_p->width * output_p->height << " data points." << std::endl;

      // Create the filtering object
      // extract.setNegative (true);
      // extract.filter (*cloud_f);
      // cloud_filtered.swap (cloud_f);


      pcl::toROSMsg (*output_p, *output);

      //Publish the results
      pub.publish(output);

}

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

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

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

  // Spin
  ros::spin ();
}

so the run time error is:

: /usr/include/boost/smart_ptr/shared_ptr.hpp:412: boost::shared_ptr<t>::reference boost::shared_ptr<t>::operator*() const [with T = sensor_msgs::PointCloud2_<std::allocator<void> >, boost::shared_ptr<t>::reference = sensor_msgs::PointCloud2_<std::allocator<void> >&]: Assertion `px != 0' failed.
Aborted

I am aware of the shared pointer issue through this post http://answers.ros.org/question/39818/ros-pcl-run-time-error-segmenting-planes/ . As a matter of fact the code developed is based on this.

I know the answer is very near ,Can you guys please help me out on this?. Thanks.

regards,
Karthik

PCL-ROS run time error while doing plane segmentation.

Hello everyone, I am trying to do plane segmentation using PCL and ROS. I am using the sensor Asus xtion pro live. I was able to launch openni_kinect and got the sensor pumping out necessary coordinates.

Here is my program:

ros::Publisher pub;
sensor_msgs::PointCloud2::Ptr downsampled,output;   



void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
pcl::PointCloud<pcl::pointxyz>::Ptr output_p(new pcl::PointCloud<pcl::pointxyz>);
pcl::PointCloud<pcl::pointxyz>::Ptr downsampled_XYZ(new pcl::PointCloud<pcl::pointxyz>);
 output_p->width=10;   
 output_p->height=10;
downsampled_XYZ->width=10;
downsampled_XYZ->height=10;
output_p->width  = 15;
  output_p->height = 1;
  output_p->points.resize (output_p->width * output_p->height);

downsampled_XYZ->width  = 15;
  downsampled_XYZ->height = 1;
  downsampled_XYZ->points.resize (output_p->width * output_p->height);


pcl::VoxelGrid<sensor_msgs::pointcloud2> sor;
sor.setInputCloud (input);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*downsampled);
// Change from type sensor_msgs::PointCloud2 to pcl::PointXYZ
pcl::fromROSMsg (*downsampled, *downsampled_XYZ);
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
// 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.setMaxIterations (1000);
      seg.setDistanceThreshold (0.01);

      // Create the filtering object
      pcl::ExtractIndices<pcl::pointxyz> extract;

      // Segment the largest planar component from the cloud
      seg.setInputCloud (downsampled_XYZ);
      seg.segment (*inliers, *coefficients);
      if (inliers->indices.size () == 0)
          {
              std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;
              }

      // Extract the inliers
      extract.setInputCloud (downsampled_XYZ);
      extract.setIndices (inliers);
      extract.setNegative (false);
      extract.filter (*output_p);
      std::cerr << "PointCloud representing the planar component: " << output_p->width * output_p->height << " data points." << std::endl;

      // Create the filtering object
      // extract.setNegative (true);
      // extract.filter (*cloud_f);
      // cloud_filtered.swap (cloud_f);


      pcl::toROSMsg (*output_p, *output);

      //Publish the results
      pub.publish(output);

}



  // Publish the model coefficients



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

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

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

  // Spin
  ros::spin ();
}
 

so the run time error is:

: /usr/include/boost/smart_ptr/shared_ptr.hpp:412: boost::shared_ptr<t>::reference boost::shared_ptr<t>::operator*() const [with T = sensor_msgs::PointCloud2_<std::allocator<void> >, boost::shared_ptr<t>::reference = sensor_msgs::PointCloud2_<std::allocator<void> >&]: Assertion `px != 0' failed.
Aborted

I am aware of the shared pointer issue through this post http://answers.ros.org/question/39818/ros-pcl-run-time-error-segmenting-planes/ . As a matter of fact the code developed is based on this.

I know the answer is very near ,Can you guys please help me out on this?. Thanks.

regards,
Karthik