zoukankan      html  css  js  c++  java
  • 计算点云法向量

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

     1 for (auto &&it : boost::filesystem::directory_iterator("/your/path")) {
     2     if (it.path().extension() == ".pcd") {
     3        std::cout << it.path() << ", " << it.path().filename() << ", " << it.path().stem() << ", " << it.path().extension() << std::endl;
     4     }
     5 }
     6 
     7 for (auto &&it : boost::filesystem::recursive_directory_iterator("/your/path")) {
     8     if (it.path().extension() == ".pcd") {
     9        std::cout << it.path() << ", " << it.path().filename() << ", " << it.path().stem() << ", " << it.path().extension() << std::endl;
    10     }
    11 }
    // 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%都是有问题的

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

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

     1     void my_normal_estimation(const KdTreePtr &kdtree, PCloudTPtr &cloud, double search_r) {
     2         for (auto &pt : cloud->points) {
     3             std::vector<int> k_indices;
     4             std::vector<float> k_sqr_distances;
     5             if (kdtree->radiusSearch(pt, search_r, k_indices, k_sqr_distances) < 3) {
     6                 continue;
     7             }
     8             PCloudTPtr cloud_search(new PCloudT);
     9             pcl::copyPointCloud(*(kdtree->getInputCloud()), k_indices, *cloud_search);
    10             pcl::PCA<PointT> pca;
    11             pca.setInputCloud(cloud_search);
    12             Eigen::Matrix3f eigen_vector = pca.getEigenVectors();
    13             Eigen::Vector3f vect_2 = eigen_vector.col(2);// please fit to your own coordinate
    14             pt.normal_x = vect_2[0];
    15             pt.normal_y = vect_2[1];
    16             pt.normal_z = vect_2[2];
    17         }
    18     }
  • 相关阅读:
    HGOI20180822 五校联考卷
    HGOI20180817 (NOIP模拟Day1 task)
    HGOI2010816 (NOIP 提高组模拟赛 day1)
    HGOI20180815 (NOIP 提高组模拟赛 day2)
    HGOI20180814 (NOIP 模拟Day1)
    HGOI20180813 (NOIP2018 提高组 Day2 模拟试题)
    小工具
    HGOI20180812 (NOIP2018 提高组 Day1 模拟试题)
    浅谈高斯消元
    浅谈线性基
  • 原文地址:https://www.cnblogs.com/wellp/p/12053048.html
Copyright © 2011-2022 走看看