计算点云的法向量

1、1.先mark一个文件操作:遍历(或者迭代遍历)指定目录,boost::filesystem可真好用

for (const auto& it : boost::filesystem::directory_iterator("/your/path")) {
    if (it.path().extension() == ".pcd") {
       std::cout << it.path() << ", " << it.path().filename() << ", " << it.path().stem() << ", " << it.path().extension() << std::endl;
    }
}

for (const auto& it : boost::filesystem::recursive_directory_iterator("/your/path")) {
    if (it.path().extension() == ".pcd") {
       std::cout << it.path() << ", " << it.path().filename() << ", " << it.path().stem() << ", " << it.path().extension() << std::endl;
    }
}// it.path()                  it.path().filename()    it.path().stem()    it.path().extension() // "/path/pairs_12_7.pcd",    "pairs_12_7.pcd",       "pairs_12_7",       ".pcd"

2.用pcl::NormalEstimation简直就是坑爹,计算出的点云法向量有40~50%都是有问题的

pcl::search::KdTree<PointS>::Ptr kdtree_submap(new pcl::search::KdTree<PointS>);
    kdtree_submap->setInputCloud(cloud_submap);// Make sure the tree searches the surface
    pcl::NormalEstimation<PointS, PointS>::Ptr ne(new pcl::NormalEstimation<PointS, PointS>);
    ne->setInputCloud(cloud_ds_angle_);
    ne->setSearchSurface(cloud_submap);
    ne->setSearchMethod(kdtree_submap);
    ne->setRadiusSearch(search_r_ne);
    ne->compute(*cloud_ds_angle_);

3、用pca和kdtree自己计算,效果赞赞赞,而且效率与上面的一样

void my_normal_estimation(const KdTreePtr &kdtree, PCloudTPtr &cloud, double search_r) {
        for (auto &pt : cloud->points) {
            std::vector<int> k_indices;
            std::vector<float> k_sqr_distances;
            if (kdtree->radiusSearch(pt, search_r, k_indices, k_sqr_distances) < 3) {
                continue;
            }
            PCloudTPtr cloud_search(new PCloudT);
            pcl::copyPointCloud(*(kdtree->getInputCloud()), k_indices, *cloud_search);
            pcl::PCA<PointT> pca;
            pca.setInputCloud(cloud_search);
            Eigen::Matrix3f eigen_vector = pca.getEigenVectors();
            Eigen::Vector3f vect_2 = eigen_vector.col(2);// please fit to your own coordinate
            pt.normal_x = vect_2[0];
            pt.normal_y = vect_2[1];
            pt.normal_z = vect_2[2];
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值