当前位置:网站首页>使用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})
边栏推荐
- There will be a black line on the border when the button in the wechat applet is clicked
- lotus 1.16.0 延长扇区过期时间
- Openresty request authentication
- Winserver operation and maintenance technology stack
- Less than a year after its establishment! MIT derivative quantum computing company completed financing of US $9million
- 静态成员static详解
- gprs网络指的是什么
- Mysql8.0 cannot authorize users or prompt you are not allowed to create a user with grant
- Static details of static members
- 2021 mathematical modeling group B exercise
猜你喜欢

105. Construct binary tree from preorder and inorder traversal sequence (medium binary tree DFS hash table binary tree)

Mysql内置函数

软考网络工程师

Research cup element recognition multi label classification task based on ernie-3.0 cail2019 method

2022年一级建造师考试什么时候才能报名?

HCIP(15)

XXX port is already in use

96. Different binary search trees (medium binary search tree dynamic planning)

CDN working principle

What is time complexity
随机推荐
Kali source solution software cannot be installed correctly
winServer运维技术栈
Sword finger offer II 057. the difference between the value and the subscript is within the given range (medium array bucket sort sliding window TreeSet)
Integrating database Ecology: using eventbridge to build CDC applications
HCIP(14)
(翻译)图技术简明历史
Overall introduction of Ruiji takeout project
Which is the file transfer command in the basic services of the Internet
静态成员static详解
Image is referred in multiple repositories
Lvs+keepalived high availability deployment practical application
Closure, prototype and original link
Leetcode question brushing series - sum of majority type
HCIP(9)
32. Longest valid bracket (difficult stack string)
Paddlenlp text classification based on ernir3.0: take wos dataset as an example (hierarchical classification)
20-09-27 the project is migrated to Alibaba toss record (the network card order makes the service unable to connect to DB through haproxy)
Sword finger offer II 065. The shortest word code (medium dictionary tree string array)
ATT&CK 威胁情报
When can I sign up for the 2022 class I constructor examination?