当前位置:网站首页>使用PCL批量显示PCD点云数据流
使用PCL批量显示PCD点云数据流
2022-07-28 20:50:00 【啥都生】

B站|公众号:啥都会一点的研究生
前言
当把某些点云文件转换成pcd形式后,一个个单帧查看实在麻烦,网上基本没啥批量处理教程,于是自己写了个批量查看代码
代码
- 首先定义流文件读取函数,将某路径下的所有文件名读入并排序
std::vector<boost::filesystem::path> streamPcd(std::string dataPath)
{
std::vector<boost::filesystem::path> paths(boost::filesystem::directory_iterator{
dataPath}, boost::filesystem::directory_iterator{
});
// sort files in accending order
sort(paths.begin(), paths.end());
return paths;
}
- 定义点云数据加载与保存函数;若一帧帧加载PCD文件并显示,点云数量大时将造成卡顿,所以先预加载
std::vector<pcl::PointCloud<pcl::PointXYZI>::Ptr> loadpt(std::vector<boost::filesystem::path> stream)
{
auto streamIterator = stream.begin();
std::vector<pcl::PointCloud<pcl::PointXYZI>::Ptr> array;
int i = 0;
while(streamIterator != stream.end()){
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud1(new pcl::PointCloud<pcl::PointXYZI>);
std::string ss((*streamIterator).string());
std::cout<< ss << std::endl;
pcl::io::loadPCDFile(ss, *cloud1);
array.push_back(cloud1);
streamIterator++;
i++;
// if (i==1000){
// break;
// }
}
return array;
}
- 需要说明的是如果仅想查看一部分pcd流,因为数据量大时加载较慢,可以通过更改if判断拿捏
- 完整代码
#include <iostream>
#include <vector>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <iostream>
#include <fstream>
std::vector<boost::filesystem::path> streamPcd(std::string dataPath)
{
std::vector<boost::filesystem::path> paths(boost::filesystem::directory_iterator{
dataPath}, boost::filesystem::directory_iterator{
});
// sort files in accending order so playback is chronological
sort(paths.begin(), paths.end());
return paths;
}
std::vector<pcl::PointCloud<pcl::PointXYZI>::Ptr> loadpt(std::vector<boost::filesystem::path> stream)
{
auto streamIterator = stream.begin();
std::vector<pcl::PointCloud<pcl::PointXYZI>::Ptr> array;
int i = 0;
while(streamIterator != stream.end()){
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud1(new pcl::PointCloud<pcl::PointXYZI>);
std::string ss((*streamIterator).string());
std::cout<< ss << std::endl;
pcl::io::loadPCDFile(ss, *cloud1);
array.push_back(cloud1);
streamIterator++;
i++;
// if (i==1000){
// break;
// }
}
return array;
}
int main()
{
std::string path = "/home/pcd/";// 此处改成你的pcd文件路径
std::vector<boost::filesystem::path> stream = streamPcd(path);
std::vector<pcl::PointCloud<pcl::PointXYZI>::Ptr> array = loadpt(stream);
int i = 0;
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
while (!viewer->wasStopped()) {
viewer->removePointCloud("sample cloud");
viewer->addPointCloud<pcl::PointXYZI>(array[i], "sample cloud");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
i = (i+1) % 1000;
viewer->spinOnce (100);
}
return 0;
}
编译
cmake_minimum_required(VERSION 3.5)
project(main)
find_package(PCL 1.2 REQUIRED)
find_package(Boost COMPONENTS program_options REQUIRED )
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries (${PROJECT_NAME} ${PCL_LIBRARIES} ${Boost_LIBRARIES})
边栏推荐
- Why doesn't the icon on the elment plus icon input display
- Netease Yunxin 2022q2 product supply station, come and get your product supply plan!
- HCIP(13)
- Sword finger offer II 063. replacement word (medium prefix tree string)
- NPM switch Taobao source (NPM source)
- Leetcode integer exercises integer inversion
- 容器化配置启动redis集群 单机6节点 3主3从
- Research cup element recognition multi label classification task based on ernie-3.0 cail2019 method
- Awk blank line filtering
- Sword finger offer II 052. flatten binary search tree (simple binary search tree DFS)
猜你喜欢

When can I sign up for the 2022 class I constructor examination?

HCIP(12)

HCIP(13)

MySQL built-in functions

Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)

ATT&CK 威胁情报

Solve Jupiter: the term 'Jupiter' is not recognized as the name of a cmdlet, function, script file

示波器发展史中的变化

Ruiji takeout - background login function development

JMeter installs third-party plug-ins plugins Manager
随机推荐
Ngx+sql environment offline installation log (RPM installation)
How to install WiFi correctly
使用webWorker执行后台任务
LeetCode刷题系列之-多数之和类型
Paddlenlp text classification based on ernir3.0: take wos dataset as an example (hierarchical classification)
SQL注入 Less38(堆叠注入)
Is mov format a still image file format
Image is referred in multiple repositories
Ngrok intranet penetration
Remember the first line segment tree (corresponding to Luogu 3372)
Establishment of Ruiji takeout development environment
Solve the problem that TS node xxx.ts executes TS code and reports errors
静态路由和缺省路由实验
Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing
NPM switch Taobao source (NPM source)
75. Color classification (medium array double pointer sorting)
ssh 免密码登录
6K6w5LiA5qyh5pS75Ye75YiG5p6Q
6K6w5LiA5qyh5pS75Ye75YiG5p6Q
Sword finger offer II 067. maximum XOR (medium prefix tree bit operation array)