当前位置:网站首页>1.读写点云文件
1.读写点云文件
2022-08-04 21:02:00 【Callmegodyu、】
1.PCD文件读写
#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
void savePcdFun()//save pcdfile
{
pcl::PointCloud<pcl::PointXYZ> cloud;
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize(cloud.width * cloud.height);
for (int i = 0; i < cloud.points.size(); ++i)
{
cloud.points[i].x = 1024 * rand() / (RAND_MAX + 0.1f);
cloud.points[i].y = 1024 * rand() / (RAND_MAX + 0.1f);
cloud.points[i].z = 1024 * rand() / (RAND_MAX + 0.1f);
}
pcl::io::savePCDFile("do1.pcd", cloud);
return;
}
void loadPcdFun()//load pcdfile
{
pcl::PointCloud<pcl::PointXYZ> cloud;
if (pcl::io::loadPCDFile("ajaccio_2 - Cloud.pcd", cloud) ==-1)
{
PCL_ERROR("load pcdfile failed!");
}
for (int i = 0; i < cloud.points.size(); ++i)
{
std::cout << cloud.points[i].x << " " << cloud.points[i].y
<< " " << cloud.points[i].z<< std::endl;
}
return;
}
}
2.点云字段或数据连接:
void concateFun()//concatenate filed
{
pcl::PointCloud<pcl::PointXYZ> cloud_a;
if (pcl::io::loadPCDFile("do1.pcd", cloud_a) == -1)
{
PCL_ERROR("load pcdfile failed !");
}
pcl::PointCloud<pcl::Normal>cloud_b_normal;
cloud_b_normal.width = 5;
cloud_b_normal.height = 1;
cloud_b_normal.is_dense = false;
cloud_b_normal.points.resize(cloud_b_normal.width * cloud_b_normal.height);
for (int i = 0; i < cloud_b_normal.points.size(); ++i)
{
cloud_b_normal.points[i].normal[0]=1024*rand()/(RAND_MAX+1.0f);
cloud_b_normal.points[i].normal[1]= 1024 * rand() / (RAND_MAX + 1.0f);
cloud_b_normal.points[i].normal[2]= 1024 * rand() / (RAND_MAX + 1.0f);
}
pcl::PointCloud<pcl::PointNormal>cloud_c;
pcl::concatenateFields(cloud_a, cloud_b_normal, cloud_c);
for (int j = 0; j < cloud_c.points.size(); ++j)
{
std::cout << cloud_c.points[j].x << " " << cloud_c.points[j].y
<< " " << cloud_c.points[j].z << " " << cloud_c.points[j].normal[0]
<< " " << cloud_c.points[j].normal[1] << " " << cloud_c.points[j].normal[2] <<
std::endl;
}
3.基于OpenNI接口的点云数据获取
#pragma
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
#include<pcl/io/openni2_grabber.h>
#include<pcl/common/time.h>
#include<pcl/visualization/cloud_viewer.h>
//读取深度信息 实时显示3d点云
class SimpleOpenNIProcessor
{
public:
pcl::visualization::CloudViewer viewer;
//construct a cloud viewer,with a window name
SimpleOpenNIProcessor() :viewer("pcl openni viewer")
{
}
//定义回调函数cloub_cb_,获取到数据时对数据进行处理
void cloud_cb_(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& cloud)
{
if (!viewer.wasStopped())
{
viewer.showCloud(cloud);
}
}
void run()
{
//create a new grabber for OpenNI Devices
pcl::Grabber* m_interface = new pcl::io::OpenNI2Grabber();
//定义回调函数
boost::function<void(pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
boost::bind(&SimpleOpenNIProcessor::cloud_cb_, this, _1);
//注册回调函数
boost::signals2::connection c = m_interface->registerCallback(f);
//start receive cloud
m_interface->start();
while (!viewer.wasStopped())
{
boost::this_thread::sleep(boost::posix_time::seconds(1));
}
//stop data aquisition
m_interface->stop();
}
};
int main()
{
SimpleOpenNIProcessor myViewer;
myViewer.run();
return 0;
}
边栏推荐
猜你喜欢
文章复现:超分辨率网络-VDSR
OD-Model【6】:YOLOv2
[Teach you to use the serial port idle interrupt of the STM32HAL library]
web漏洞扫描器-awvs
1、File对象学习
用 Excel 爬取网络数据的四个小案例
Five Minutes Introductory Text Processing Three Musketeers grep awk sed
如何进行AI业务诊断,快速识别降本提效增长点?
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
How to understand the crawler's Scrapy framework in the simplest and most popular way?
随机推荐
How to understand the crawler's Scrapy framework in the simplest and most popular way?
两种白名单限流方案(redis lua限流,guava方案)
漫画 | 老板裁掉我两周后,又把我请回去,工资翻番!
伺服电机矢量控制原理与仿真(1)控制系统的建立
[2022 Nioke Duo School 5 A Question Don't Starve] DP
【2022杭电多校5 1003 Slipper】多个超级源点+最短路
27.降维
五分钟入门文本处理三剑客grep awk sed
Web3时代的战争
for 循环中的 ++i 与 i++
使用百度EasyDL实现森林火灾预警识别
【编程思想】
用 Excel 爬取网络数据的四个小案例
adb控制常用命令
js的new Function()常用方法
Web3安全风险令人生畏,应该如何应对?
【C语言】指针和数组的深入理解(第三期)
3、IO流之字节流和字符流
零知识证明——zkSNARK证明体系
bracket matching