以下是基于1.8.1版本的PCL库,使用C++编写的代码,用于查找点云PLY文件中已知点p的索引:

#include <iostream>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>

int main()
{
    // 加载点云PLY文件
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPLYFile<pcl::PointXYZ>(’input.ply’, *cloud);

    // 已知点p的坐标
    pcl::PointXYZ p;
    p.x = 1.0;
    p.y = 2.0;
    p.z = 3.0;

    // 查找点p的索引
    int index = -1;
    for (size_t i = 0; i < cloud->size(); ++i)
    {
        if ((*cloud)[i].x == p.x && (*cloud)[i].y == p.y && (*cloud)[i].z == p.z)
        {
            index = i;
            break;
        }
    }

    // 输出点p的索引
    if (index != -1)
    {
        std::cout << ’Point p is found at index: ’ << index << std::endl;
    }
    else
    {
        std::cout << ’Point p is not found in the point cloud.’ << std::endl;
    }

    return 0;
}

请将代码中的’input.ply’替换为实际的PLY文件路径,并根据需要修改已知点p的坐标。代码将输出点p在点云中的索引,如果点p不存在于点云中,则输出相应的提示信息。

C++代码:使用PCL库查找PLY点云文件中已知点的索引

原文地址: https://www.cveoy.top/t/topic/fFEi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录