C++ PCL库:获取std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> 中所有点云的点数

以下代码示例展示了如何使用C++和PCL库来获取一个包含多个点云数据的std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>容器中每个点云的点数。

#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

int main()
{
    std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> yezi;

    // 假设yezi中有三个点云数据
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud1(new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud2(new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud3(new pcl::PointCloud<pcl::PointXYZRGB>);

    // 设置每个点云的点数
    cloud1->width = 100;
    cloud1->height = 1;
    cloud1->points.resize(cloud1->width * cloud1->height);

    cloud2->width = 200;
    cloud2->height = 1;
    cloud2->points.resize(cloud2->width * cloud2->height);

    cloud3->width = 50;
    cloud3->height = 1;
    cloud3->points.resize(cloud3->width * cloud3->height);

    // 将点云添加到yezi中
    yezi.push_back(cloud1);
    yezi.push_back(cloud2);
    yezi.push_back(cloud3);

    // 输出每个点云的点数
    for (int i = 0; i < yezi.size(); i++)
    {
        std::cout << "PointCloud " << i + 1 << " has " << yezi[i]->points.size() << " points." << std::endl;
    }

    return 0;
}

这段代码首先创建了一个std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> yezi,然后创建了三个点云数据cloud1cloud2cloud3,并分别设置了它们的点数。接着将这三个点云数据添加到yezi中。最后使用循环遍历输出每个点云的点数。

C++ PCL库:获取std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> 中所有点云的点数

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

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