欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

点云pcd格式与ply格式互相转换

程序员文章站 2022-03-31 09:35:44
...

1. pcd转ply

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

using namespace std;

int main()
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloudOrigin(new pcl::PointCloud<pcl::PointXYZ>);
    //pcl::PLYReader reader;
    pcl::PCDReader reader;
    reader.read("D:\\MatLab\\workspace\\Point-cloud-Edge-and-Corner-Detection-master\\data\\panel_line3.pcd", *cloudOrigin);
    
    /*for循环避免出现数据中出现nan*/
    for (int i = 0; i < cloudOrigin->points.size(); i++)
    {
        if (isnan(cloudOrigin->points[i].x))
        {
            cloudOrigin->points[i].x = 0;
            cloudOrigin->points[i].y = 0;
            cloudOrigin->points[i].z = 0;
        }
    }
    //pcl::PCDWriter writer;
    pcl::PLYWriter writer;
    writer.write("D:\\MatLab\\workspace\\Point-cloud-Edge-and-Corner-Detection-master\\data\\panel_line3.ply", *cloudOrigin);
    cout << "finished..." << endl;
    return 0;
}

2. ply转pcd

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

using namespace std;

int main()
{
    pcd::PointCloud<pcl::PointXYZ>::Ptr cloudOrigin(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PLYReader reader;
    reader.read("D:\\MatLab\\workspace\\Point-cloud-Edge-and-Corner-Detection-master\\data\\panel_line3.ply", *cloudOrigin);
    
    pcl::PCDWriter writer;
    writer.writeASCII("D:\\MatLab\\workspace\\Point-cloud-Edge-and-Corner-Detection-master\\data\\panel_line3.pcd", *cloudOrigin);
    cout << "finished..." << endl;
    return 0;
}