2015-06-10 171 views
1

我可以使用此程序讀取.pcd數據。如何使用PCL讀取.ply文件

#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>); 

    if (pcl::io::loadPCDFile<pcl::PointXYZ> ("airplane.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 (size_t i = 0; i < cloud->points.size(); ++i) 
    std::cout << " " << cloud->points[i].x 
       << " " << cloud->points[i].y 
       << " " << cloud->points[i].z << std::endl; 

    return (0); 
} 

如何閱讀.ply文件我在10號線做了以下變化:

if (pcl::io::loadPLYFile<pcl::PointXYZ> ("airplane.ply", *cloud) == -1) //* load the file 

它給comilation錯誤。

所以我改寫爲:

if (pcl::io::loadPCDFile<pcl::PointXYZ> ("airplane.ply", *cloud) == -1) //* load the file 

現在,它給了我運行時錯誤:

[pcl::PCDReader::readHeader] No points to read 
Couldn't read file test_pcd.pcd 

如何解決這個問題?

回答

5

函數pcl::io::loadPLYFile()的確是您應該用來讀取PLY文件的東西。要解決編譯問題,請確保包含適當的頭文件(pcl/io/ply_io.h)。

0

我們也可以創建一個PLYReader作爲PCDReader如下圖所示讀取PLY文件和所有的點到所需的雲

#include<pcl/io/ply_io.h> 

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ); 
pcl::PLYReader Reader; 
Reader.read("Path of the PLY file", *cloud);