#include <iostream> #include <pcl/io/pcd_io.h> //pcd流头文件 #include <pcl/point_types.h> //点类型即现成的pointT int main(int argc, char** argv) { //创建点云指针 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); //直接读取pcd文件到cloud中,并判断是否读取正确 if (pcl::io::loadPCDFile<pcl::PointXYZ>("rabbit.pcd", *cloud) == -1) //* load the file { PCL_ERROR("Couldn't read file test_pcd.pcd \n"); return (-1); } // 控制台输出点云宽高(无序点云为总数) std::cout << "Loaded " << cloud->width * cloud->height << " data points from test_pcd.pcd with the following fields: " << std::endl; // 遍历点云输出坐标 for (const auto& point : *cloud) std::cout << " " << point.x << " " << point.y << " " << point.z << std::endl; return (0); }该程序优化成是使用于vs2022和pcl1.13.1读取pcd_v7的程序
时间: 2024-03-26 10:34:29 浏览: 176
好的,您可以将您的代码修改如下以适应pcl1.13.1和pcd_v7:
```cpp
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int main(int argc, char** argv) {
// 创建点云指针
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 直接读取pcd文件到cloud中,并判断是否读取正确
if (pcl::io::loadPCDFile<pcl::PointXYZ>("rabbit.pcd", *cloud) == -1) //* load the file
{
PCL_ERROR("Couldn't read file rabbit.pcd \n");
return (-1);
}
// 控制台输出点云宽高(无序点云为总数)
std::cout << "Loaded "
<< cloud->size()
<< " data points from rabbit.pcd with the following fields: "
<< std::endl;
// 遍历点云输出坐标
for (const auto& point : *cloud)
std::cout << " " << point.x
<< " " << point.y
<< " " << point.z << std::endl;
return (0);
}
```
这里,您需要将PointCloud的大小从width * height更改为size(),因为在pcd_v7中没有高度和宽度的概念,而是使用size()来表示点云中点的数量。另外,请确保将文件名更改为您要读取的pcd文件名。
阅读全文