13419585995 发表于 2017-12-13 15:31:11

计算spinimage和shape_context特征时出错,求大神帮忙解答

这是pcl特征提取的示例代码,对点云提取spin_image特征
#include <iostream>
#include <vector>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/spin_image.h>
int
main(int, char** argv)
{
std::string filename = argv;
std::string save_file1 = filename.substr(0, filename.find(".pcd")) + "_spinimage.txt";
std::cout << "Reading " << filename << std::endl;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile <pcl::PointXYZ>(filename.c_str(), *cloud) == -1)

{
PCL_ERROR("Couldn't read file");
return (-1);
}
std::cout << "Loaded " << cloud->points.size() << " points." << std::endl;
// 计算法向量
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimation;
normal_estimation.setInputCloud(cloud);
pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>);
normal_estimation.setSearchMethod(kdtree);
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud< pcl::Normal>);
normal_estimation.setRadiusSearch(0.35);
normal_estimation.compute(*normals);
// 计算spin_image特征
pcl::SpinImageEstimation<pcl::PointXYZ, pcl::Normal, pcl::Histogram<153> > spin_image_descriptor(8, 0.5, 16);
spin_image_descriptor.setInputCloud(cloud);
spin_image_descriptor.setInputNormals(normals);
// Use the same KdTree from the normal estimation
spin_image_descriptor.setSearchMethod(kdtree);
pcl::PointCloud<pcl::Histogram<153> >::Ptr spin_images(new pcl::PointCloud<pcl::Histogram<153> >);
spin_image_descriptor.setRadiusSearch(0.6);
// Actually compute the spin images
spin_image_descriptor.compute(*spin_images);
std::cout << "SI output points.size (): " << spin_images->points.size() << std::endl;
// 将特征写入txt文件
std::ofstream ofs1;
ofs1.open(save_file1);
for (size_t i = 0; i != spin_images->points.size(); ++i)
{
size_t size = spin_images->points.descriptorSize();
for (size_t j = 0; j != size - 1; ++j)
   ofs1 << spin_images->points.histogram << "\t";
ofs1 << spin_images->points.histogram << "\n";
}
ofs1.close();
std::system("pause");
return 0;
}
运行到compute函数时就报错
Unhandled exception at 0x00007FF81E4D7788 in rift.exe: Microsoft C++ exception: pcl::PCLException at memory location 0x00000069116FEFF0.


页: [1]
查看完整版本: 计算spinimage和shape_context特征时出错,求大神帮忙解答