Я следил за учебником PCL Извлечение евклидова кластера . Код был скомпилирован без ошибок, но при запуске он дает мне следующую ошибку
PointCloud representing the planar component: 2874 data points. Segmentation fault (core dumped)
Здесь исходные облака точек и исходное изображение
Здесь код
ros::Publisher pub, markers_pub_;
void cloud_cb(const sensor_msgs::PointCloud2::ConstPtr &msg){
//Voxel Filtering
// Convert ros_pcl2 to pcl2
pcl::PCLPointCloud2::Ptr input_cloud (new pcl::PCLPointCloud2 ());
pcl_conversions::toPCL(*msg,*input_cloud);
//Deklaration cloud pointers for Voxel
pcl::PCLPointCloud2::Ptr cloud_filtered_voxel (new pcl::PCLPointCloud2 ());
//Voxel Filter
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (input_cloud);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered_voxel);
//StatisticalOutlierRemoval Filetring
//Convert pcl2 to pclxyzrgba
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_sor_input (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::fromPCLPointCloud2(*cloud_filtered_voxel, *cloud_sor_input);
//Deklaration cloud pointers for SOR
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_sor_filtered (new pcl::PointCloud<pcl::PointXYZRGB>);
//statistical outliner removal
pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> sor1;
sor1.setInputCloud (cloud_sor_input);
sor1.setMeanK (6);
sor1.setStddevMulThresh (0.04);
sor1.filter (*cloud_sor_filtered);
//Deklaration cloud pointers
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered_x(new pcl::PointCloud<pcl::PointXYZRGB>);
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered_y(new pcl::PointCloud<pcl::PointXYZRGB>);
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered_z(new pcl::PointCloud<pcl::PointXYZRGB>);
// Get segmentation ready
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_plane (new pcl::PointCloud<pcl::PointXYZRGB> ());
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_f (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
pcl::SACSegmentation<pcl::PointXYZRGB> seg;
pcl::ExtractIndices<pcl::PointXYZRGB> extract;
seg.setOptimizeCoefficients (true);
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setMaxIterations (100);// orig bez ova
seg.setDistanceThreshold(0.09); //original 0.09
// Create pointcloud to publish inliers
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_pub(new pcl::PointCloud<pcl::PointXYZRGB>);
int i=0, nr_points = (int) cloud_sor_filtered->points.size ();
while (cloud_sor_filtered->points.size () > 0.1 * nr_points)
{
// Segment the largest planar component from the remaining cloud
seg.setInputCloud (cloud_sor_filtered);
seg.segment (*inliers, *coefficients);
if (inliers->indices.size () == 0)
{
std::cout << "Could not estimate a planar model for the given dataset." << std::endl;
break;
}
// Extract the planar inliers from the input cloud
pcl::ExtractIndices<pcl::PointXYZRGB> extract;
extract.setInputCloud (cloud_sor_filtered);
extract.setIndices (inliers);
extract.setNegative (false);
// Get the points associated with the planar surface
extract.filter (*cloud_plane);
std::cout << "PointCloud representing the planar component: " << cloud_plane->points.size () << " data points." << std::endl;
// Remove the planar inliers, extract the rest
extract.setNegative (true);
extract.filter (*cloud_f);
*cloud_sor_filtered = *cloud_f;
}
// Euclidean Cluster
// Creating the KdTree object for the search method of the extraction
pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB>);
tree->setInputCloud (cloud_sor_filtered);// cloud_sor_filtered
// create the extraction object for the clusters
std::vector<pcl::PointIndices> *cluster_indices;
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_box (new pcl::PointCloud<pcl::PointXYZRGB> ());
pcl::EuclideanClusterExtraction<pcl::PointXYZRGB> ec;
// specify euclidean cluster parameters
ec.setClusterTolerance (0.09); // 2cm
ec.setMinClusterSize (100);
ec.setMaxClusterSize (25000);
ec.setSearchMethod (tree);
ec.setInputCloud (cloud_sor_filtered);// cloud_sor_filtered
ec.extract (*cluster_indices);
sensor_msgs::PointCloud2 cloud_publish;
pcl::toROSMsg(*cloud_f, cloud_publish);
pub.publish(cloud_publish);
}
int
main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "my_pcl_tutorial");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe ("/zed/zed_node/point_cloud/cloud_registered", 200, cloud_cb);
pub = nh.advertise<sensor_msgs::PointCloud2> ("cloud_publish", 100);
markers_pub_ = nh.advertise<visualization_msgs::MarkerArray> ("msg_marker", 200);
ros::spin();
}
Помощь? После кластеризации означает, что после ec.extract (*cluster_indices);
я также пробовал это
std::vector<sensor_msgs::PointCloud2::Ptr> pc2_clusters;
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr > clusters;
for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it)
{
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster (new pcl::PointCloud<pcl::PointXYZRGB> ());
for (std::vector<int>::const_iterator pit = it->indices.begin (); pit != it->indices.end (); pit++)
cloud_cluster->points.push_back(cloud_sor_filtered->points[*pit]);
cloud_cluster->width = cloud_cluster->points.size ();
cloud_cluster->height = 1;
cloud_cluster->is_dense = true;
//std::cout << "Cluster has " << cloud_cluster->points.size() << " points.\n";
clusters.push_back(cloud_cluster);
sensor_msgs::PointCloud2::Ptr tempROSMsg(new sensor_msgs::PointCloud2);
pcl::toROSMsg(*cloud_cluster, *tempROSMsg);
pub.publish(tempROSMsg);
}
, но все еще не смог визуализировать кластеры. Пожалуйста, помогите? Спасибо