当前位置:网站首页>Using PCL to batch display PCD point cloud data flow
Using PCL to batch display PCD point cloud data flow
2022-07-28 22:38:00 【Everything】

B standing | official account : A graduate student who knows everything
Preface
When converting some point cloud files into pcd After form , It's really troublesome to check single frames , There are basically no batch processing tutorials online , So I wrote a batch check code
Code
- First, define the stream file reading function , Read in and sort all file names under a certain path
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;
}
- Define point cloud data loading and saving functions ; If one frame is loaded PCD File and display , A large number of point clouds will cause a jam , So preload first
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;
}
- It should be noted that if you only want to view a part pcd flow , Because the load is slow when the amount of data is large , You can change it if Judge carefully
- Complete code
#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/";// Change this to yours pcd File path
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;
}
compile
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})
边栏推荐
- Remember the first line segment tree (corresponding to Luogu 3372)
- 近期bug总结
- 静态成员static详解
- Closure, prototype and original link
- 容器化配置启动redis集群 单机6节点 3主3从
- XXX port is already in use
- Detection and tracking evaluation index
- Is mov format a still image file format
- LeetCode刷题系列之-多数之和类型
- [Ruiji takeout project]day4 - dish management
猜你喜欢

Static route and default route experiment

flask之蓝图 补充openpyxl
![[connect set-top box] - use ADB command line to connect ec6108v9 Huawei Yuehe box wirelessly](/img/ab/624e9a3240416f8445c908378310ad.png)
[connect set-top box] - use ADB command line to connect ec6108v9 Huawei Yuehe box wirelessly
![[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints](/img/37/7cb5fa3a9078a5f5947485147c819d.png)
[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints

Install PCL and VTK under the background of ROS installation, and solve VTK and PCL_ ROS conflict problem

SQL injection less38 (Stack Injection)

STM32 - reset and clock control (cubemx for clock configuration)

842. 排列数字

使用PCL批量显示PCD点云数据流

What is time complexity
随机推荐
【转载】token令牌在登录场景使用
[get mobile information] - get mobile information through ADB command
Kali source solution software cannot be installed correctly
MySQL built-in functions
[leetcode] maximum depth of binary tree
[binary tree] pseudo palindrome path in binary tree
Install PCL and VTK under the background of ROS installation, and solve VTK and PCL_ ROS conflict problem
842. 排列数字
Wechat applet uses canvas drawing, round avatar, network background, text, dotted line, straight line
[Ruiji takeout project]day4 - dish management
Att & CK Threat Intelligence
c语言实现字符串逆序排列
internet的基本服务中文件传输命令是哪个
775. 倒排单词
gprs网络指的是什么
Integrating database Ecology: using eventbridge to build CDC applications
NPM switch Taobao source (NPM source)
Win11 how to open software notification
Target segmentation learning
Paddlenlp is based on ernir3.0 text classification. Take the traditional Chinese medicine search and retrieval semantic map classification (kuake-qic) as an example [multi classification (single label