求助
我装的PCL-1.13.1+vs2022,环境变量也都配置成功了
可以运行代码
// 创建点云对象
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 定义正方体的尺寸
float length = 1.0f;
// 添加正方体顶点数据
for (float x = -length / 2; x <= length / 2; x += 0.1f)
{
for (float y = -length / 2; y <= length / 2; y += 0.1f)
{
for (float z = -length / 2; z <= length / 2; z += 0.1f)
{
pcl::PointXYZ point;
point.x = x;
point.y = y;
point.z = z;
cloud->push_back(point);
}
}
}
// 设置点云属性
cloud->width = cloud->size();
cloud->height = 1;
cloud->is_dense = true;
// 保存点云为PCD文件
pcl::io::savePCDFileASCII("cube.pcd", *cloud);
std::cout << "Saved " << cloud->size() << " data points to cube.pcd." << std::endl;
return 0;
并且保存生成了一个名为cube.pcd的点云文件,但是我在利用
pcl::io::loadPCDFile<pcl::PointXYZ>(file_path, *cloud)
读取这个生成的pcd文件时一直报错,报错信息如下:
[pcl::PCDReader::read] Could not find file 'P毨$?'.
而且出现的还是乱码,我的文件路径不含中文和特殊字符
file_path = "D:\\pcd_files\\cube.pcd"
我的电脑系统windows11(也不知道跟这个有关系没)
我读取pcd的代码如下:
string file_path;
cout << "Enter the absolute path of PCD file: ";
getline(cin, file_path);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 读取PCD文件
if (pcl::io::loadPCDFile<pcl::PointXYZ>(R"(file_path)", *cloud) == -1)
{
PCL_ERROR("Failed to read PCD file\n");
while (true) {
std::string out;
std::cin >> out;
if (out == "00") {
break;
}
}
return -1;
}
// 输出点云信息
std::cout << "Loaded " << cloud->size() << " data points from cube.pcd" << std::endl;