python读取pcd文件_(一)读取PCD文件

下面是一个简单的读取PCD文件并显示的代码:

#include

#include

#include

#include

#include

void main()

{

/* Create Point Cloud */

pcl::PointCloud<:pointxyzrgba>::Ptr cloud(new pcl::PointCloud<:pointxyzrgba>);

/* Read PCD File */

/* Read Wrong */

if (- == pcl::io::loadPCDFile<:pointxyzrgba>("table_scene_lms400.pcd", *cloud))

{

return;

}

/* Then show the point cloud */

boost::shared_ptr<:visualization::pclvisualizer> viewer(new pcl::visualization::PCLVisualizer("office chair model"));

viewer->setBackgroundColor(, , );

pcl::visualization::PointCloudColorHandlerRGBField<:pointxyzrgba> rgba(cloud); //Maybe set the cloud to he handler rgba?

viewer->addPointCloud<:pointxyzrgba>(cloud, rgba, "sample cloud"); //Add a Point Cloud (templated) to screen. Q:Some questions here

viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , "sample cloud"); //Set the rendering properties

//viewer->addCoordinateSystem(1.0); //Adds 3D axes describing a coordinate system to screen at 0,0,0

viewer->initCameraParameters (); //Initialize camera parameters with some default values.

/* Show the point cloud */

while (!viewer->wasStopped ())

{

viewer->spinOnce (); //updates the screen loop

boost::this_thread::sleep (boost::posix_time::microseconds ());

}

}

pcl::io::loadPCDFile用于读取一个PCD文件至一个PointCloud类型,这里就是将table_scene_lms400.pcd文件里的数据读取至cloud里。

在PCL文档里关于pcl::io::loadPCDFile的实现有3个,我目前只看了第一种。

下面看看loadPCDFile在namespace io里的实现:

template inline int

loadPCDFile (const std::string &file_name, pcl::PointCloud &cloud)

{

pcl::PCDReader p;

return (p.read (file_name, cloud));

}

可以看到loadPCDFile 这个内联函数,就是调用了一下pcl::PCDReader里的read函数。

继续看PCDReader函数:

template int

read (const std::string &file_name, pcl::PointCloud &cloud, const int offset = 0)

{

pcl::PCLPointCloud2 blob;

int pcd_version;

int res = read (file_name, blob, cloud.sensor_origin_, cloud.sensor_orientation_, pcd_version, offset);

// If no error, convert the data

if (res == 0)

pcl::fromPCLPointCloud2 (blob, cloud);

return (res);

}

最后在pdc_io.cpp里找到代码:

int

pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,

Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version,

const int offset)

{

pcl::console::TicToc tt;

tt.tic ();

int data_type;

unsigned int data_idx;

int res = readHeader (file_name, cloud, origin, orientation, pcd_version, data_type, data_idx, offset);

if (res < )

return (res);

unsigned int idx = ;

// Get the number of points the cloud should have

unsigned int nr_points = cloud.width * cloud.height;

// Setting the is_dense property to true by default

cloud.is_dense = true;

if (file_name == "" || !boost::filesystem::exists (file_name))

{

PCL_ERROR ("[pcl::PCDReader::read] Could not find file '%s'.\n", file_name.c_str ());

return (-);

}

// if ascii

if (data_type == )

{

// Re-open the file (readHeader closes it)

std::ifstream fs;

fs.open (file_name.c_str ());

if (!fs.is_open () || fs.fail ())

{

PCL_ERROR ("[pcl

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值