基于Rangenet Lib的自动驾驶LiDAR点云语义分割与可视化

这段代码是一个C++程序,用于处理来自KITTI数据集的激光雷达(LiDAR)扫描数据。程序主要实现以下功能:

1. **读取和解析命令行参数**:使用Boost库中的`program_options`模块来定义和解析命令行参数。这包括扫描文件路径、模型路径以及是否启用详细模式(verbose)。

2. **处理KITTI数据集中的LiDAR扫描数据**:程序遍历指定KITTI数据集目录中的LiDAR扫描数据(`.bin`格式)。这些数据包含了LiDAR扫描的点云信息。

3. **LiDAR数据的语义分割**:使用`rangenet_lib`库创建一个网络模型来进行语义分割。这个库用于为LiDAR点云数据提供语义标签,例如将点分类为车辆、行人、道路等。

4. **读取和处理每个扫描文件**:对每个扫描文件,程序读取点云数据,并使用创建的网络模型进行推理(infer),得到每个点的语义标签。

5. **转换点云数据**:获取转换后的点云数据和颜色掩膜(color mask),这些颜色表示不同的语义类别。

6. **保存语义分割结果**:将每个点的坐标和对应的颜色标签保存到文本文件中。这些文件用于可视化或进一步分析处理。

7. **可视化(可选)**:如果启用了详细模式(verbose),则使用OpenCV的可视化工具(`cv::viz`)来显示语义分割后的点云。

总的来说,这个程序的主要作用是处理KITTI数据集中的LiDAR点云数据,通过使用语义分割网络对每个点进行分类,然后将分类结果保存并(可选地)进行可视化展示。这对于自动驾驶、机器人导航等领域的研究和应用是非常有用的。

1. infer中的内容 

/* Copyright (c) 2019 lifeiya, Chongqing University.**  This file is part of advanced rangenet_lib.**/// opencv stuff
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/viz.hpp>// c++ stuff
#include <chrono>
#include <iomanip>  
#include <iostream>
#include <string>
#include <sstream>// net stuff
#include <selector.hpp>
namespace cl = rangenet::segmentation;// boost
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;typedef std::tuple< u_char, u_char, u_char> color;int main(int argc, const char *argv[]) {// define optionsstd::string scan;std::string path;std::string backend = "tensorrt";// 如果verbose为true,则程序会输出更多的运行过程信息,如果为false,则只输出最基本的信息。bool verbose = false;std::ostringstream scanStream;std::string kitti_num = "10"; // Replace "01" with the actual value you wantstd::string base_path = "/home/fairlee/dataset/KITTI/sequences_kitti_00_21/" + kitti_num + "/velodyne/";std::string file_extension = ".bin";// Calculate the number of files in the directoryint N = std::distance(fs::directory_iterator(base_path), fs::directory_iterator{});for(int file_num = 1000; file_num < N; ++file_num) {// cout<<"正在处理-----"<<file_num<<"/"<< N <<"数据"<<endl;std::cout << std::left << "正在处理 " <<kitti_num<< " 数据集中的第: "<< file_num << " / "  << N << " 帧数据" << std::endl;// Parse optionstry {po::options_description desc{"Options"};desc.add_options()("help,h", "Help screen")("scan,s", po::value<std::string>(&scan),"LiDAR scan to infer. No Default")("path,p", po::value<std::string>(),"Directory to get the inference model from. No default")("verbose,v", po::bool_switch(),"Verbose mode. Calculates profile (time to run)");po::variables_map vm;po::store(parse_command_line(argc, argv, desc), vm);po::notify(vm);std::cout << std::setfill('=') << std::setw(80) << "" << std::endl;if (vm.count("help")) {std::cout << desc << std::endl;return 0;}std::ostringstream scanStream;scanStream << base_path << std::setfill('0') << std::setw(6) << file_num << file_extension;scan = scanStream.str();// make defaults count, parameter check, and printpath = "/home/fairlee/darknet53/";if (vm.count("verbose")) {verbose = vm["verbose"].as<bool>();std::cout << "verbose: " << verbose << std::endl;} else {std::cout << "verbose: " << verbose << ". Using default!" << std::endl;}std::cout << std::setfill('=') << std::setw(80) << "" << std::endl;} catch (const po::error &ex) {std::cerr << ex.what() << std::endl;return 1;}// create a networkstd::unique_ptr<cl::Net> net = cl::make_net(path, backend);// set verbositynet->verbosity(verbose);// predict each imagestd::cout << std::setfill('=') << std::setw(80) << "" << std::endl;std::cout << "Predicting image: " << scan << std::endl;// Open a scanstd::ifstream in(scan.c_str(), std::ios::binary);if (!in.is_open()) {std::cerr << "Could not open the scan!" << std::endl;return 1;}in.seekg(0, std::ios::end);uint32_t num_points = in.tellg() / (4 * sizeof(float));in.seekg(0, std::ios::beg);std::vector<float> values(4 * num_points);in.read((char*)&values[0], 4 * num_points * sizeof(float));// predictstd::vector<std::vector<float>> semantic_scan = net->infer(values, num_points);// get point cloudstd::vector<cv::Vec3f> points = net->getPoints(values, num_points);// get color maskstd::vector<cv::Vec3b> color_mask = net->getLabels(semantic_scan, num_points);// Create output filenamestd::ostringstream outfileNameStream;outfileNameStream << "/home/fairlee/dataset/KITTI/sequences_kitti_00_21/" << kitti_num << "/RangeNet_point/" << std::setfill('0') << std::setw(6) << file_num << ".txt";std::string outfileName = outfileNameStream.str();// Create an ofstream objectstd::ofstream outfile(outfileName);if (!outfile) {std::cerr << "Unable to open output file: " << outfileName << std::endl;return 1;}// Iterate through each point and corresponding colorfor (size_t i = 0; i < points.size(); ++i) {// Write the point coordinates and color to the fileoutfile << points[i][0] << " " << points[i][1] << " " << points[i][2];outfile << " " << static_cast<int>(color_mask[i][0]) << " " << static_cast<int>(color_mask[i][1]) << " " << static_cast<int>(color_mask[i][2]) << "\n";}// Close the fileoutfile.close();Create an ofstream object
//std::ofstream outfile("output.txt");Iterate through each point and corresponding color
//for (size_t i = 0; i < points.size(); ++i) {
//  // Write the point coordinates and color to the file
//  outfile << points[i][0] << " " << points[i][1] << " " << points[i][2];
//  outfile << " " << static_cast<int>(color_mask[i][0]) << " " << static_cast<int>(color_mask[i][1]) << " " << static_cast<int>(color_mask[i][2]) << "\n";
//}Close the file
//outfile.close();// print the outputif (verbose) {cv::viz::Viz3d window("semantic scan");cv::viz::WCloud cloudWidget(points, color_mask);while (!window.wasStopped()) {window.showWidget("cloud", cloudWidget);window.spinOnce(30, true);}}std::cout << std::setfill('=') << std::setw(80) << "" << std::endl;std::cout << "Example finished! "<< std::endl;}return 0;
}

2. 编译通过后运行

3. 运行结果(也可以保存为pcd)

4. 完整代码的github 连接

https://github.com/RobotsRuning/RangeNet_ws/tree/main

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/592452.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

docker安装postgresql15或者PG15

1. 查询版本 docker search postgresql docker pull postgres:15.3 # 也可以拉取其他版本2.运行容器并挂载数据卷 mkdir -p /data/postgresql docker run --name postgres \--restartalways \-e POSTGRES_PASSWORDpostgresql \-p 5433:5432 \-v /data/postgresql:/var/lib/p…

使用函数求余弦函数的近似值

本题要求实现一个函数&#xff0c;用下列公式求cos(x)的近似值&#xff0c;精确到最后一项的绝对值小于e&#xff1a; cos(x)x0/0!−x2/2!x4/4!−x6/6!⋯ 本题&#xff1a;需注意x的0次方为1,0的阶乘为1 #include <stdio.h> #include <math.h> double funcos(…

计算机网络-以太网交换基础

一、网络设备的演变 最初的网络在两台设备间使用传输介质如网线等进行连接就可以进行通信。但是随着数据的传输需求&#xff0c;多个设备需要进行数据通信时就需要另外的设备进行网络互联&#xff0c;并且随着网络传输的需求不断更新升级。从一开始的两台设备互联到企业部门内部…

【LeetCode 面试经典150题】26. Remove Duplicates from Sorted Array 在有序数组中移除重复元素

26. Remove Duplicates from Sorted Array 题目大意 Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then …

Nginx多ip部署多站点

目录 1.修改网卡配置信息 2.修改主要配置文件nginx.conf 1.修改网卡配置信息 1)来到网卡配置文件存放目录下 cd /etc/sysconfig/network-scripts/ 2)对 ifcfg-ens33 文件进行配置修改前先进行备份 cp ifcfg-ens33 ifcfg-ens33.default 3)先修改成最小配置&#xff0c;使用 d…

MySQL运维实战(2.1) 登录失败次数太多导致主机被锁住的问题处理

作者&#xff1a;俊达 引言 当我们在使用 MySQL 时&#xff0c;可能遇到过如下类似的错误&#xff1a; Host IP is blocked because of many connection errors; unblock with mysqladmin flush-hosts该错误意味着 mysqld 已从给定主机收到许多中断的连接请求。并且数量超过…

在线H5网页版植物大战僵尸游戏源代码

源码介绍 HTML5植物大战僵尸网页版游戏源码&#xff0c;直接把源码上传到服务器就能使用和访问

GIT使用简介

Git 是一种版本控制系统&#xff0c;常用于团队协作开发和管理代码。下面是 Git 的基本使用方式&#xff1a; 安装 Git&#xff1a;首先&#xff0c;在你的计算机上安装 Git。你可以从 Git 官方网站&#xff08;https://git-scm.com/&#xff09;下载适合你操作系统的版本&…

裁员+失恋或许不能比这更遭了,敬一塌糊涂与充满感动的2023,也敬曾经的挚爱与寒冬的冰霜

~ 随机抽取评论区的 3位 小伙伴送上精美礼品 ~ 参与方式&#xff1a;关注、点赞、收藏&#xff0c;评论 "2024&#xff0c;一天当做两天卷&#xff01;" 活动时间&#xff1a;截止到 2024-01-21 00:00:00 礼品清单&#xff1a;CSDN活动周边、自选图书 本文目录 序 …

React实现拖拽效果

基于 React 的拖拽效果 Demo 一个基于 React 的拖拽功能实现的 Demo. 两个关键点 1, draggable 属性 2, drag 事件 draggable 属性 img 标签默认是支持拖拽的, 当时其他 HTML 标签, 想要其拖动的话, 需要为其添加 draggable“true” 属性 drag 事件 drag 相关的事件有:…

C++ STL set用法详解

我们都知道&#xff0c;set是STL里的一种数据结构&#xff0c;这篇博客就是set用法的详解。 1.set的创建。 set初始化一般是 set<数据结构名称> 名字; 具体例子&#xff1a; 创建一个int型&#xff0c;名称是s的set。 set<int> s; set还可以创建STL里的数据…

创建express服务器的快捷方式

第一步&#xff1a;打开cmd&#xff08;创建服务器的目录&#xff09;&#xff1b;创建 express 名字 第二步&#xff1a;cd 名字进入 第三步&#xff1a;下载一个npm i 第四步&#xff1a;在文件下接口那里输入nodemon/npm start 启动 条件查询&#xff1a;$gt $lt $gte…

Element-ui自定义input框非空校验

1、vue自定义非空指令&#xff1a; main.js中自定义非空指令 当input框或下拉框中数据更新时&#xff0c;触发校验 Vue.directive(isEmpty,{update:function(el,binding,vnode){if(vnode.componentInstance.value""){el.classList.add("is-required");}e…

2024更新腾讯云轻量应用服务器优惠价格表和CVM优惠活动

腾讯云服务器租用价格表&#xff1a;轻量应用服务器2核2G3M价格62元一年、2核2G4M价格118元一年&#xff0c;540元三年、2核4G5M带宽218元一年&#xff0c;2核4G5M带宽756元三年、轻量4核8G12M服务器446元一年、646元15个月&#xff0c;云服务器CVM S5实例2核2G配置280.8元一年…

LVDS接口ADC数据处理流程案例参考

一ADC&#xff1a; 16bit精度DDRLVDS8个outpin 二&#xff1a;FPGA处理流程&#xff1a; 1.差分数据转单端idelaye2generate for generate for(i0;i<7;ii1)begin:GEN_IN IBUFDS #(.DIFF_TERM("TRUE"), // Differential Termination.IBUF_LOW_PWR("F…

分布式【zookeeper面试题12连问】

1. 面试官&#xff1a;工作中使用过Zookeeper嘛&#xff1f;你知道它是什么&#xff0c;有什么用途呢&#xff1f; 「小菜鸡的我&#xff1a;」 有使用过的&#xff0c;使用ZooKeeper作为**「dubbo的注册中心」&#xff0c;使用ZooKeeper实现「分布式锁」**。ZooKeeper&#…

k8s中实现pod自动扩缩容

一、k8s应用自动扩缩容概述 1&#xff09;背景&#xff1a; 在实际的业务场景中&#xff0c;我们经常会遇到某个服务需要扩容的场景&#xff08;例如&#xff1a;测试对服务压测、电商平台秒杀、大促活动、或由于资源紧张、工作负载降低等都需要对服务实例数进行扩缩容操作&…

openCV处理音视频的常用API及一般流程

OpenCV是一个功能强大的开源计算机视觉库&#xff0c;提供了丰富的API和函数&#xff0c;用于图像处理、特征提取、目标检测等任务。下面是一些常用的OpenCV API及其在C中的使用方法&#xff1a; 1. 图像读取和显示&#xff1a; #include <opencv2/opencv.hpp>int ma…

【PostgreSQL】约束-主键

【PostgreSQL】约束链接 检查 唯一 主键 外键 排他 主键 主键&#xff08;Primary Key&#xff09;是数据库表中用于唯一标识每一行记录的字段。主键具有以下特点&#xff1a; 唯一性&#xff1a;每个主键值在表中是唯一的&#xff0c;不允许出现重复值。非空性&#xff1a…

vue3(十三)-基础入门之路由配置与重定向

一、一级路由与重定向 1、创建 App.vue 在父组件中导入子组件 Navbar <template><div><navbar></navbar></div> </template><style lang"scss"></style><script> import navbar from /components/Navbarex…