PCL发布构建崩溃而无法分配
PCL Release Build crashes with Failed to Allocate
我是PCL和C 的新手。我有这个代码,该代码将飞机置于点云中。该代码在调试模式下运行良好。但是,释放配置不断使用[InitCompute]崩溃,无法分配34263047索引。索引数量在每次尝试中都在不断变化。
不确定需要做什么,我认为PCL使用智能指针,这意味着我不必明确发布参考文献。
关于如何解决的任何想法?我正在附加我的代码以供参考。
原始云尺寸13698107过滤云尺寸44196[Initcompute]未能分配34263047指数。
环境:PCL 1.8.0vs 2015社区Windows 10
感谢您的时间。
#include <iostream>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/passthrough.h>
#include <pcl/segmentation/region_growing.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/sample_consensus/ransac.h>
#include <pcl/sample_consensus/sac_model_plane.h>
#include <pcl/octree/octree.h>
#include <boost/filesystem.hpp>
typedef pcl::PointXYZ PointT;
std::vector<double> split_axis_vectors(std::string input, char delimiter) {
std::vector<double> result;
std::stringstream ss(input); // Turn the string into a stream.
std::string tok;
std::string::size_type sz;
while (getline(ss, tok, delimiter)) {
result.push_back(std::stod(tok));
}
return result;
}
std::vector<std::string> split_axis(std::string input, char delimiter) {
std::vector<std::string> result;
std::stringstream ss(input); // Turn the string into a stream.
std::string tok;
std::string::size_type sz;
while (getline(ss, tok, delimiter)) {
result.push_back(tok);
}
return result;
}
bool segment_planes(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,
pcl::PointCloud<pcl::Normal>::Ptr normal,
Eigen::Vector3f axis,
int modelType,
double epsAngle) {
int nr_points = (int)cloud->points.size();
//pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_plane(new pcl::PointCloud<pcl::PointXYZ >);
//pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_p(new pcl::PointCloud<pcl::PointXYZ>);
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());
pcl::PointIndices::Ptr inliers(new pcl::PointIndices());
pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg;
//pcl::ExtractIndices<pcl::PointXYZ> extract;
//pcl::ExtractIndices<pcl::Normal> extract_normals;
// Temporary Objects for swapping
//pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_tmp(new pcl::PointCloud<pcl::PointXYZ>);
//pcl::PointCloud<pcl::Normal>::Ptr cloud_normals_tmp(new pcl::PointCloud<pcl::Normal>);
// Segment Planes Vertical
seg.setOptimizeCoefficients(true);
seg.setModelType(modelType);
seg.setNormalDistanceWeight(0.1);
seg.setMethodType(pcl::SAC_RANSAC);
seg.setMaxIterations(100);
seg.setDistanceThreshold(0.2);
seg.setAxis(axis);
seg.setEpsAngle(epsAngle);
seg.setInputNormals(normal);
seg.setInputCloud(cloud);
seg.segment(*inliers, *coefficients);
if (inliers->indices.size() > 0 &&
inliers->indices.size() >= nr_points * 0.5) {
return true;
}
else {
return false;
}
}
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr full_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCLPointCloud2::Ptr cloud_blob(new pcl::PCLPointCloud2), cloud_filtered_blob(new pcl::PCLPointCloud2);
std::vector<std::string> axises = split_axis(argv[3], ';'); // Get individual axis seperated by ;
std::string out_dir = argv[2];
// Fill in the cloud data
pcl::PCDReader reader;
reader.read(argv[1], *cloud_blob);
pcl::fromPCLPointCloud2(*cloud_blob, *full_cloud);
// Create SAC Model plane to test fitting of downsized cloud
pcl::SampleConsensusModelPlane<pcl::PointXYZ>::Ptr model_p(new pcl::SampleConsensusModelPlane<pcl::PointXYZ>(full_cloud));
std::cout << "Original Cloud Size " << cloud_blob->width * cloud_blob->height << std::endl;
pcl::search::Search<pcl::PointXYZ>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZ> > (new pcl::search::KdTree<pcl::PointXYZ>);
pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>);
float leaf_size = 0.5f;
// Create the filtering object: downsample the dataset using a leaf size of 1cm
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud(cloud_blob);
sor.setLeafSize(leaf_size, leaf_size, leaf_size);
sor.filter(*cloud_filtered_blob);
// Convert to the templated PointCloud
pcl::fromPCLPointCloud2(*cloud_filtered_blob, *cloud);
std::cout << "Filtered Cloud Size " << cloud->points.size() << std::endl;
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimator;
normal_estimator.setSearchMethod (tree);
normal_estimator.setInputCloud (cloud);
normal_estimator.setKSearch (25);
normal_estimator.compute (*normals);
pcl::RegionGrowing<pcl::PointXYZ, pcl::Normal> reg;
reg.setMinClusterSize (100);
reg.setMaxClusterSize (1000000);
reg.setSearchMethod (tree);
reg.setNumberOfNeighbours (15);
reg.setInputCloud (cloud);
reg.setInputNormals (normals);
reg.setSmoothnessThreshold (5.0 / 180.0 * M_PI);
reg.setCurvatureThreshold (1.0);
std::vector <pcl::PointIndices> clusters;
reg.extract (clusters);
int no_clusters = clusters.size();
std::cout << "Number of clusters is equal to " << no_clusters << std::endl;
pcl::PointIndices::Ptr all_perp_indices(new pcl::PointIndices());
all_perp_indices->indices.clear();
pcl::PointIndices::Ptr all_parallel_indices(new pcl::PointIndices());
all_parallel_indices->indices.clear();
std::vector<Eigen::VectorXf> parallel_model_coffs;
std::vector<Eigen::VectorXf> perpendicular_model_coffs;
std::vector<int> perp_planes_indices;
std::vector<int> parallel_planes_indices;
pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(leaf_size);
octree.setInputCloud(full_cloud);
octree.addPointsFromInputCloud();
for (int idx = 0; idx < no_clusters; idx = idx + 1) {
std::cout << "Number of points in "<< idx << " is equal to " << clusters[idx].indices.size() << std::endl;
//region_indices.insert(region_indices.end(), clusters[idx].indices.begin(), clusters[idx].indices.end());
pcl::ExtractIndices<pcl::PointXYZ> extract;
pcl::ExtractIndices<pcl::Normal> extract_normals;
pcl::PointCloud<pcl::PointXYZ>::Ptr cluster_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::Normal>::Ptr cluster_normals(new pcl::PointCloud<pcl::Normal>);
pcl::PointIndices::Ptr cluster_inliers(new pcl::PointIndices());
cluster_inliers->indices.clear();
cluster_inliers->header = clusters[idx].header;
cluster_inliers->indices = clusters[idx].indices;
all_perp_indices->header = clusters[idx].header;
all_parallel_indices->header = clusters[idx].header;
// Extract the point cloud inliers in cluster
extract.setInputCloud(cloud);
extract.setIndices(cluster_inliers);
extract.setNegative(false);
extract.filter(*cluster_cloud); // Get Points in plane
// Extact the point normal inliers in cluster
extract_normals.setNegative(false);
extract_normals.setInputCloud(normals);
extract_normals.setIndices(cluster_inliers);
extract_normals.filter(*cluster_normals);
// Test perpendicular and parallel for all axis combinations
for (int aIdx = 0; aIdx < axises.size(); aIdx = aIdx + 1) {
std::vector<double> axis = split_axis_vectors(axises[aIdx], ',');
// Segment Parallel Planes
bool perp_plane_cloud = segment_planes(cluster_cloud,
cluster_normals,
Eigen::Vector3f(axis[0], axis[1], axis[2]),
pcl::SACMODEL_PERPENDICULAR_PLANE,
20.0f * 0.0174533f);
if (perp_plane_cloud) {
int n_perp_plane_point = cluster_cloud->points.size();
for (int pp_Idx = 0; pp_Idx < n_perp_plane_point; pp_Idx = pp_Idx + 1) {
pcl::PointXYZ searchPoint = cluster_cloud->points[pp_Idx];
std::vector<int> perp_inliers;
if (octree.voxelSearch(searchPoint, perp_inliers)) {
all_perp_indices->indices.insert(all_perp_indices->indices.end(), perp_inliers.begin(), perp_inliers.end());
}
}
}
// Segment Parallel Planes
bool parallel_plane_cloud = segment_planes(cluster_cloud,
cluster_normals,
Eigen::Vector3f(axis[1] * -1, axis[0], axis[2]),
pcl::SACMODEL_PERPENDICULAR_PLANE,
20.0f * 0.0174533f);
if (parallel_plane_cloud) {
int n_parallel_plane_point = cluster_cloud->points.size();
for (int pl_Idx = 0; pl_Idx < n_parallel_plane_point; pl_Idx = pl_Idx + 1) {
pcl::PointXYZ searchPoint = cluster_cloud->points[pl_Idx];
std::vector<int> parallel_inliers;
if (octree.voxelSearch(searchPoint, parallel_inliers)) {
all_parallel_indices->indices.insert(all_parallel_indices->indices.end(), parallel_inliers.begin(), parallel_inliers.end());
}
}
}
}
}
// Extract Perpendicular Planes
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_perp(new pcl::PointCloud<pcl::PointXYZ>);
pcl::ExtractIndices<pcl::PointXYZ> extract_perp;
extract_perp.setInputCloud(full_cloud);
extract_perp.setIndices(all_perp_indices);
extract_perp.setNegative(false);
extract_perp.filter(*cloud_perp);
if (cloud_perp->points.size() > 0) {
pcl::io::savePCDFileBinaryCompressed(out_dir + "\reg_segment_perp.pcd", *cloud_perp);
}
// Extract Parallel Planes
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_parallel(new pcl::PointCloud<pcl::PointXYZ>);
pcl::ExtractIndices<pcl::PointXYZ> extract_parallel;
extract_parallel.setInputCloud(full_cloud);
extract_parallel.setIndices(all_parallel_indices);
extract_parallel.setNegative(false);
extract_parallel.filter(*cloud_parallel);
if (cloud_parallel->points.size() > 0) {
pcl::io::savePCDFileBinaryCompressed(out_dir + "\reg_segment_parallel.pcd", *cloud_parallel);
}
return (0);
}
riyas
安装PCL很难,因为与PCL软件一起使用了数十种依赖项。但是使用VCPKG,安装变得像一个衬里命令一样。
使用Microsoft VCPKG自动为您的项目构建静态库。诸如Boost,Tiff,OpenSSL,Flann,Szip等的所有依赖项将被单独下载和安装。安装VCPKG后,在PowerShell上键入以下内容。
.vcpkg install pcl:x64-windows-static
我认为您正在使用错误的Flan库。尝试在释放模式下重建绒布,并仅使用绒布DLL。希望它有帮助。
相关文章:
- c++11:在VS2015中分配全局STL "map<string, string>" initializer_list崩溃
- 分配内存并在回调时调用C++的 Rust 函数崩溃
- STD :: FSTREAM在使用预先分配的内存时在Main之后崩溃
- 当我尝试将一个向量元素的值分配给另一个向量元素时,为什么我的应用程序会崩溃
- 在崩溃时释放分配的指针的正确方法
- PCL发布构建崩溃而无法分配
- 当我释放由CFFI生成的DLL分配的char*时,为什么我的应用程序会崩溃
- 为什么在复制构造函数中分配联合成员会崩溃
- 在构造函数[C ]中的FP分配上崩溃
- 矢量未正确擦除内容(复制分配运算符的量运行直到崩溃 [BEX])
- 程序在解除分配字符数组时崩溃
- 删除在不同函数中动态分配的对象时崩溃
- 如果在进程崩溃后在进程中分配内存,会发生什么情况
- CComPtrBase::~解除分配智能指针时,CComPtr Base崩溃
- 删除矢量元素指向的已分配内存会导致程序崩溃
- 矩阵分配导致崩溃
- 释放动态分配的内存时程序崩溃
- Boost.SSpirit.Qi在将规则分配给包括自身在内的序列时崩溃
- QString分配崩溃
- 程序崩溃(动态内存分配)