pcl之I/O输入输出
Posted chriscoder
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pcl之I/O输入输出相关的知识,希望对你有一定的参考价值。
pcl之I/O输入输出
Reading Point Cloud data from PCD files
#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> ("test_pcd.pcd", *cloud) == -1) //* load the file
{
PCL_ERROR ("Couldn't read file test_pcd.pcd
");
return (-1);
}
return (0);
}
Writing Point Cloud data to PCD files
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
// Fill in the cloud data
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize (cloud.width * cloud.height);
for (size_t i = 0; i < cloud.points.size (); ++i)
{
cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
}
pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;
for (size_t i = 0; i < cloud.points.size (); ++i)
std::cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
return (0);
}
Concatenate the points of two Point Clouds
- If we are trying to concatenate points then the code below:
cloud_c = cloud_a;
cloud_c += cloud_b;
creates cloud_c by concatenating the points of cloud_a and cloud_b together.
- Otherwise if we are attempting to concatenate fields then the code below:
pcl::concatenateFields (cloud_a, n_cloud_b, p_n_cloud_c);
creates p_n_cloud_c by concatenating the fields of cloud_a and cloud_b together.
以上是关于pcl之I/O输入输出的主要内容,如果未能解决你的问题,请参考以下文章
第四章输入/输出(I/O)4.1I/O涉及的设备及相关概念简介