PCL库导入点云模型以及常见问题分析

PCL程序运行后先加载所有的点云坐标,被刷屏了,等待时间较长。
我上传了免费的兔子点云模型,链接见https://download.csdn.net/download/Asabc12345/12488127
PCL库导入点云模型以及常见问题分析_第1张图片
PCL库导入点云模型以及常见问题分析_第2张图片


#include  //标准输入输出流
#include  //PCL的PCD格式文件的输入输出头文件
#include  //PCL的ply格式文件的输入输出头文件
#include  //PCL对各种格式的点的支持头文件
#include 

int main(int argc, char** argv)
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // 创建点云(指针)

	if (pcl::io::loadPLYFile<pcl::PointXYZ>("C:\\Users\\fhlhc\\Desktop\\点云模型\\rabbit.ply", *cloud) == -1) //* 读入PCD格式的文件,如果文件不存在,返回-1
	{
		PCL_ERROR("Couldn't read file test_pcd.pcd \n"); //文件不存在时,返回错误,终止程序。
		return (-1);
	}
	std::cout << "Loaded "
		<< cloud->width * cloud->height
		<< " data points from test_file.pcd with the following fields: "
		<< std::endl;
	for (size_t i = 0; i < cloud->points.size(); ++i) //显示所有的点
	//for (size_t i = 0; i < cloud->size(); ++i) // 为了方便观察,只显示前5个点
		std::cout << "    " << cloud->points[i].x
		<< " " << cloud->points[i].y
		<< " " << cloud->points[i].z << std::endl;
	pcl::visualization::CloudViewer viewer("pcd viewer");
	viewer.showCloud(cloud);
	system("pause");
	return (0);
}

//#include
//#include//标准C++库中的输入输出类相关头文件。
//#include
//#include//pcd 读写类相关的头文件。
//#include
//#include //PCL中支持的点类型头文件。
//int user_data;
//using std::cout;
//
//
//void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) {
//    viewer.setBackgroundColor(1.0, 0.5, 1.0);   //设置背景颜色
//}
//
//int main() {
//    pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
//
//    char strfilepath[256] = "E:\\intern\\rabbit.pcd";
//    if (-1 == pcl::io::loadPCDFile(strfilepath, *cloud)) {
//        cout << "error input!" << endl;
//        return -1;
//    }
//
//    cout << cloud->points.size() << endl;
//    pcl::visualization::CloudViewer viewer("Cloud Viewer");     //创建viewer对象
//
//    viewer.showCloud(cloud);
//    viewer.runOnVisualizationThreadOnce(viewerOneOff);
//    system("pause");
//    return 0;
//}
//

常见问题:
1.运行后不报错但是不显示,输出-1。
问题分析:点云模型格式或者文件有问题,换一个文件试试。
#include //PCL的PCD格式文件的输入输出头文件
#include //PCL的ply格式文件的输入输出头文件
这两个头文件代表点云的格式,如果你是ply的格式,但是只加载了PCD的头文件,是运行不出来的,检查头文件少没少。
注意加载不同格式点云时,loadPCDFile这里也要改,导入ply格式的话就要把PCD改成loadPLYFile。
在这里插入图片描述

2.报错
parse error: couldn’t read the magic string
[pcl::PLYReader::read] problem parsing header!
[pcl::PLYReader::read] problem parsing header!
Couldn’t read ply file

错误分析:路径什么都没问题的话,我也没找到具体的原因,反正我后来换了点云模型重新加载就解决了

如果只是想简单的调用点云读取或者显示不做进一步研究的话,只需要用其他成熟的商业软件比如MeshLab,傻瓜无脑操作,新手友好哈哈哈PCL库导入点云模型以及常见问题分析_第3张图片

你可能感兴趣的:(点云,读取,meshlab,c++)