How to read .ply file using PCL

非 Y 不嫁゛ 提交于 2019-12-05 02:00:21

问题


I can read .pcd data using this program.

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

How to read a .ply file i made the following change in line 10:

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

It gave comilation error.

SO i rewrote as:

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

Now it gave me run-time error:

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

How to resolve this?


回答1:


The function pcl::io::loadPLYFile() is indeed what you should use to read PLY files. To solve the compilation problem, make sure that you include appropriate header file (pcl/io/ply_io.h).




回答2:


We can also create a PLYReader as the PCDReader as shown below to read the PLY file and all the points to the required cloud

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


来源:https://stackoverflow.com/questions/30764222/how-to-read-ply-file-using-pcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!