📜  PCL 正常特定点 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:35.632000             🧑  作者: Mango

代码示例1
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
int main()
{
    
    //--------------------- Load point cloud data ----------------------
    pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
    if (pcl::io::loadPCDFile(" Car point cloud .pcd", *cloud) == -1)
    {
    
        PCL_ERROR("Could not read file\n");
    }
    //-------------- Calculate the front of the cloud 10% The point normal of -----------------------
    vector point_indices(floor(cloud->points.size() / 10));
    for (size_t i = 0; i < point_indices.size(); ++i) {
    
        point_indices[i] = i;    
    }
    //------------------- Pass index ----------------------------
    pcl::IndicesPtr indices(new vector (point_indices));
    //------------------- Calculating normals ----------------------------
    pcl::NormalEstimationOMP n;//OMP Speed up 
    n.setInputCloud(cloud);
    n.setIndices(indices);
    //  Create a kd Trees , Easy to search ; And pass it to the normal estimation class object created above 
    pcl::search::KdTree::Ptr tree(new pcl::search::KdTree());
    n.setSearchMethod(tree);
    n.setRadiusSearch(0.01);
    pcl::PointCloud::Ptr normals(new pcl::PointCloud);
    //---------------- Estimate characteristics ---------------
    n.compute(*normals);
    //------------- For convenience of visualization , Before the 10% Point cloud puts forward -------------------------------
    pcl::PointCloud::Ptr cloud1(new pcl::PointCloud);
    pcl::copyPointCloud(*cloud, point_indices, *cloud1);
    //------------------ visualization -----------------------
    boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("Normal viewer"));
    // Set the background color 
    viewer->setBackgroundColor(0.3, 0.3, 0.3);
    viewer->addText("faxian", 10, 10, "text");
    // Set the point cloud color 
    pcl::visualization::PointCloudColorHandlerCustom single_color1(cloud1, 0, 225, 0);
    pcl::visualization::PointCloudColorHandlerCustom single_color(cloud, 255, 0, 0);
    // Add coordinate system 
    //viewer->addCoordinateSystem(0.1);
    viewer->addPointCloud(cloud, single_color, "sample cloud");
    viewer->addPointCloud(cloud1, single_color1, "sample cloud1");
    viewer->addPointCloudNormals(cloud1, normals, 20, 0.02, "normals");
    // Set the point cloud size 
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "sample cloud1");
    while (!viewer->wasStopped())
    {
    
        viewer->spinOnce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    }

    return 0;
}