PCL tutorial "Extracting indications from a PointCloud" cannot be built

Asked 2 years ago, Updated 2 years ago, 89 views

I would like to use PCL to extract the plane from the point group.
There is a tutorial on PCL that says "Extracting indications from a PointCloud", and when I tried to run this code, I got the following error when I built it using cmake:

I copied the code in the tutorial and built it, so I think it's probably a library error, but I don't know why.Could someone tell me the solution?

extract_indices.cpp

#include<iostream>
# include <pcl/ModelCoefficients.h>
# include <pcl/io/pcd_io.h>
# include <pcl/point_types.h>
# include <pcl/sample_consensus/method_types.h>
# include <pcl/sample_consensus/model_types.h>
# include<pcl/segmentation/sac_segmentation.h>
# include <pcl/filters/voxel_grid.h>
# include <pcl/filters/extract_indices.h>

int
main(interargc, char**argv)
{
  sensor_msgs::PointCloud2::Ptrcloud_blob(new sensor_msgs::PointCloud2), 
  cloud_filtered_blob(new sensor_msgs::PointCloud2);
  pcl::PointCloud<pcl::PointXYZ>::Ptrcloud_filtered (new pcl::PointCloud<pcl::PointXYZ>), 
  cloud_p(newpcl::PointCloud<pcl::PointXYZ>), cloud_f(new 
  pcl::PointCloud<pcl::PointXYZ>);

  // Fill in the cloud data
  pcl::PCDReader reader;
  reader.read("table_scene_lms400.pcd", *cloud_blob);

  std::cerr<<"PointCloud before filtering:"<cloud_blob->width*cloud_blob->height<<;; 
  " data points."<<std::endl;

  // Create the filtering object: downsample the dataset using a leaf size of 1cm
  pcl::VoxelGrid<sensor_msgs::PointCloud2>sor;
  sor.setInputCloud(cloud_blob);
  sor.setLeafSize(0.01f, 0.01f, 0.01f);
  sor.filter(*cloud_filtered_blob);

  // Convert to the template PointCloud
  pcl::fromROSMsg(*cloud_filtered_blob,*cloud_filtered);

  std::cerr<<"PointCloud after filtering:"<cloud_filtered->width*cloud_filtered- 
  >height<<"data points."<<std::endl;

  // Write the downsampled version to disk
  pcl::PCDWriter writer;
  writer.write<pcl::PointXYZ>("table_scene_lms400_downsampled.pcd", *cloud_filtered, 
  false);

  pcl::ModelCoefficients::Ptrcoefficients (new pcl::ModelCoefficients());
  pcl::PointIndices::Ptrinliers (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;

  inti=0,nr_points=(int)cloud_filtered->points.size();
  // While 30% of the original cloud is still there
  while(cloud_filtered->points.size()>0.3*nr_points)
  {
    // Segment the large plan component from the remaining cloud
    seg.setInputCloud(cloud_filtered);
    seg.segment(*inliers,*coefficials);
    if (inliers->indices.size()==0)
    {
      std::cerr<<"Could not estimate a planar model for the given dataset."<<std::endl;
      break;
    }

    // Extract the inliers
    extract.setInputCloud(cloud_filtered);
    extract.setIndices(inliers);
    extract.setNegotistical(false);
    extract.filter(*cloud_p);
    std::cerr<<"PointCloud presenting the planar component:"<<cloud_p->width* 
    cloud_p->height<<"data points."<std::endl;

    std::stringstreams;
    ss<"table_scene_lms400_plane_"<i<<.".pcd";
    writer.write<pcl::PointXYZ>(ss.str(), *cloud_p, false);

    // Create the filtering object
    extract.setNegotistical(true);
    extract.filter(*cloud_f);
    cloud_filtered.swap(cloud_f);
    i++;
  }

  return(0);
}

Build Results

/home/-------/pcl/extract_indices/extract_indices.cpp:In function 'int main(int, char**)':
/home/-------/pcl/extract_indices/extract_indices.cpp:15:8:error:'pcl::PointCloud2' has not 
be de-declared
   pcl::PointCloud2::Ptrcloud_blob(new sensor_msgs::PointCloud2), cloud_filtered_blob(new sensor_msgs::PointCloud2);
        ^~~~~~~~~~~
/home/-------/pcl/extract_indices/extract_indices.cpp:20:43:error:'cloud_blob'was not detailed in this scope
   reader.read("table_scene_lms400.pcd", *cloud_blob);
                                           ^~~~~~~~~~
/home/-------/pcl/extract_indices/extract_indices.cpp:20:43:note:suggested alternative:'cloud_f'
   reader.read("table_scene_lms400.pcd", *cloud_blob);
                                           ^~~~~~~~~~
                                           cloud_f
/home/-------/pcl/extract_indices/extract_indices.cpp:25:18:error: 'sensor_msgs' was not decoded in this scope
   pcl::VoxelGrid<sensor_msgs::PointCloud2>sor;
                  ^~~~~~~~~~~
/home/-------/pcl/extract_indices/extract_indices.cpp:25:42:error:template argument 1 is invalid
   pcl::VoxelGrid<sensor_msgs::PointCloud2>sor;
                                          ^
/home/-------/pcl/extract_indices/extract_indices.cpp:26:7: error: request for member 'setInputCloud' in 'sor', which is of non-class type 'int'
   sor.setInputCloud(cloud_blob);
       ^~~~~~~~~~~~~
/home/-----/pcl/extract_indices/extract_indices.cpp:27:7:error:request for member 'setLeafSize' in 'sor', which is of non-class type 'int'
   sor.setLeafSize(0.01f, 0.01f, 0.01f);
       ^~~~~~~~~~~
/home/-------/pcl/extract_indices/extract_indices.cpp:28:7: error: request for member 'filter' in 'sor', which is of non-class type 'int'
   sor.filter(*cloud_filtered_blob);
       ^~~~~~
/home/-------/pcl/extract_indices/extract_indices.cpp:28:16:error: 'cloud_filtered_blob' was not decoded in this scope
   sor.filter(*cloud_filtered_blob);
                ^~~~~~~~~~~~~~~~~~~
/home/-------/pcl/extract_indices/extract_indices.cpp:28:16:note:suggested alternative: 'cloud_filtered'
   sor.filter(*cloud_filtered_blob);
                ^~~~~~~~~~~~~~~~~~~
                cloud_filtered
/home/-------/pcl/extract_indices/extract_indices.cpp:31:8:error: 'fromROSMsg' is not a member of 'pcl'
   pcl::fromROSMsg(*cloud_filtered_blob,*cloud_filtered);
        ^~~~~~~~~~
File included from /home/-----/pcl/extract_indices/extract_indices.cpp:6:0:
/usr/include/pcl-1.8/pcl/sample_consensus/model_types.h: In function 'void_static_initialization_and_destruction_0(int, int)':
/usr/include/pcl-1.8/pcl/sample_consensus/model_types.h:99:3:warning:'pcl::SAC_SAMPLE_SIZE' is deprecated: This map is decremented and iskept only to preempt breaking existing user code.Starting from PCL1.8.0 model of sample size is the size.
   SAC_SAMPLE_SIZE(sample_size_pairs, sample_size_pairs + sizeof(sample_size_pairs)/sizeof(SampleSizeModel));
   ^~~~~~~~~~~~~~~
/usr/include/pcl-1.8/pcl/sample_consensus/model_types.h:99:3:note:declared here
CMakeFiles/extract_indices.dir/build.make:62—recipe for target 
'CMakeFiles/extract_indices.dir/extract_indices.cpp.o' failed
make[2]:*** [CMakeFiles/extract_indices.dir/extract_indices.cpp.o] Error 1
CMakeFiles/Makefile2:67:recipe for target'CMakeFiles/extract_indices.dir/all'failed
make[1]:***[CMakeFiles/extract_indices.dir/all] Error 2
Makefile:83:recipe for target 'all' failed
make: ***[all] Error 2

c++ ubuntu build cmake

2022-09-29 21:45

1 Answers

It seems that the version of the site I referred to was old.
I tried the latest version of the tutorial and successfully built it.


2022-09-29 21:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.