使用cv::ximgproc::FastBilateralSolverFilter优化realsense D455的深度图

1 源码

OpenCV中内置了很多滤波器,这里我们讨论cv::ximgproc其中包含的滤波器。
https://docs.opencv.org/3.4/da/d17/group__ximgproc__filters.html
需要注意的是,默认安装的OpenCV中不包含cv::ximgproc,请从源码重修编译。
在这里插入图片描述
在这里贴上我的测试源码。

/*
cv::ximgproc::AdaptiveManifoldFilter
[86] Eduardo SL Gastal and Manuel M Oliveira. Adaptive manifolds for real-time high-dimensional filtering. ACM Transactions on Graphics (TOG), 31(4):33, 2012.cv::ximgproc::EdgeAwareInterpolator
[182] Jerome Revaud, Philippe Weinzaepfel, Zaid Harchaoui, and Cordelia Schmid. Epicflow: Edge-preserving interpolation of correspondences for optical flow. In Computer Vision and Pattern Recognition (CVPR), IEEE Conference on, pages 1164–1172, 2015.cv::ximgproc::DTFilter
[85] Eduardo SL Gastal and Manuel M Oliveira. Domain transform for edge-aware image and video processing. In ACM Transactions on Graphics (TOG), volume 30, page 69. ACM, 2011.cv::ximgproc::DisparityWLSFiltercv::ximgproc::FastBilateralSolverFilter
[14] Jonathan T Barron and Ben Poole. The fast bilateral solver. In European Conference on Computer Vision (ECCV), pages 617–632. Springer International Publishing, 2016.cv::ximgproc::FastGlobalSmootherFilter
[158] Dongbo Min, Sunghwan Choi, Jiangbo Lu, Bumsub Ham, Kwanghoon Sohn, and Minh N Do. Fast global image smoothing based on weighted least squares. Image Processing, IEEE Transactions on, 23(12):5638–5653, 2014.
[66] Zeev Farbman, Raanan Fattal, Dani Lischinski, and Richard Szeliski. Edge-preserving decompositions for multi-scale tone and detail manipulation. In ACM Transactions on Graphics (TOG), volume 27, page 67. ACM, 2008.cv::ximgproc::GuidedFilter
[99] Kaiming He, Jian Sun, and Xiaoou Tang. Guided image filtering. In Computer Vision–ECCV 2010, pages 1–14. Springer, 2010.cv::ximgproc::RidgeDetectionFilter
[64] Niki Estner. Best way of segmenting veins in leaves.
[151] Wolfram Mathematica. Ridge filter mathematica.*/#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ximgproc.hpp>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>#include <pcl/point_types.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/common/common.h>
#include <pcl/common/pca.h>
#include <Eigen/Dense>class ImageProcessor
{
public:ImageProcessor(): it_(nh_), image_sub_(nh_, "/camera/color/image_raw", 1), depth_sub_(nh_, "/camera/aligned_depth_to_color/image_raw", 1){typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> MySyncPolicy;// ApproximateTime或者ExactTimesync_.reset(new message_filters::Synchronizer<MySyncPolicy>(MySyncPolicy(10), image_sub_, depth_sub_));sync_->registerCallback(boost::bind(&ImageProcessor::callback, this, _1, _2));pub_ = it_.advertise("/fbs/depth_processed", 1);cloud_pub_ = nh_.advertise<pcl::PointCloud<pcl::PointXYZRGB>>("/fbs/output_cloud", 1);cloud2_pub_ = nh_.advertise<pcl::PointCloud<pcl::PointXYZRGB>>("/fbs/output_cloud2", 1);}void callback(const sensor_msgs::ImageConstPtr& color_msg, const sensor_msgs::ImageConstPtr& depth_msg){cv::Mat color_image, depth_image;try {color_image = cv_bridge::toCvShare(color_msg, "rgb8")->image;depth_image = cv_bridge::toCvShare(depth_msg, sensor_msgs::image_encodings::TYPE_16UC1)->image;cv::Mat confidence;generateConfidence(depth_image, confidence);// 将confidence图像标准化到0-255的范围cv::Mat normalized_confidence;confidence.convertTo(normalized_confidence, CV_8UC1, 255.0); // 将浮点值乘以255以进行转换// // 显示信心图// cv::namedWindow("Confidence", cv::WINDOW_AUTOSIZE); // 创建一个窗口// cv::imshow("Confidence", normalized_confidence);    // 显示信心图// cv::waitKey(1); // 等待1毫秒,让显示函数有机会更新窗口cv::Mat filtered_image;applyFastBilateralSolverFilter(depth_image, color_image, confidence, filtered_image);// applyFastGlobalSmootherFilter(depth_image, color_image, filtered_image);// applyGuidedFilter(depth_image, color_image, filtered_image);// applyRidgeDetectionFilter(depth_image, filtered_image);// 转换回ROS图像并发布sensor_msgs::ImagePtr msg_out = cv_bridge::CvImage(std_msgs::Header(), sensor_msgs::image_encodings::TYPE_16UC1, filtered_image).toImageMsg();pub_.publish(msg_out);// 发布点云pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());depthToPointCloud(depth_image, color_image, *cloud);cloud->header.stamp = pcl_conversions::toPCL(color_msg->header.stamp); // Use the correct message for the timestampcloud_pub_.publish(cloud);// 发布点云// pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());depthToPointCloud(filtered_image, color_image, *cloud);// cloud->header.stamp = pcl_conversions::toPCL(color_msg->header.stamp); // Use the correct message for the timestampcloud2_pub_.publish(cloud);} catch (const cv_bridge::Exception& e) {ROS_ERROR("cv_bridge exception: %s", e.what());return;}}void generateConfidence(const cv::Mat &depth, cv::Mat &confidence){confidence = cv::Mat::zeros(depth.size(), CV_32F);confidence.setTo(1, depth != 0);}void applyFastBilateralSolverFilter(const cv::Mat &depth, const cv::Mat &color, const cv::Mat &confidence, cv::Mat &output){auto filter = cv::ximgproc::createFastBilateralSolverFilter(color, 10, 1, 10);filter->filter(depth, confidence, output);}void applyFastGlobalSmootherFilter(const cv::Mat &depth, const cv::Mat &color, cv::Mat &output){// 将depth转换为16S格式cv::Mat depth16S;depth.convertTo(depth16S, CV_16S);// 创建Fast Global Smoother滤波器auto filter = cv::ximgproc::createFastGlobalSmootherFilter(color, 128, 10);// 使用16S格式的depth进行滤波filter->filter(depth16S, output);}void applyGuidedFilter(const cv::Mat &depth, const cv::Mat &color, cv::Mat &output){// 将depth图像转换为CV_32F类型cv::Mat depth32F;cv::Mat output32F;depth.convertTo(depth32F, CV_32F, 1.0 / 255.0);auto filter = cv::ximgproc::createGuidedFilter(color, 5, 0.01);filter->filter(depth32F, output32F);output32F.convertTo(output, CV_16U, 255.0);}void applyRidgeDetectionFilter(const cv::Mat &depth, cv::Mat &output){// 将图像转换为浮点类型,这是脊线检测滤波器的要求cv::Mat depth32F;depth.convertTo(depth32F, CV_32FC1, 1.0 / 255.0);// 创建脊线检测滤波器int ddepth = -1; // 使用相同的图像深度作为输入和输出double scale = 1; // Sobel算子的比例因子double delta = 0; // 添加到结果中的可选增量值int borderType = cv::BORDER_DEFAULT; // 边缘填充方式cv::Ptr<cv::ximgproc::RidgeDetectionFilter> ridgeFilter = cv::ximgproc::RidgeDetectionFilter::create();// 应用脊线检测滤波器cv::Mat output32F;ridgeFilter->getRidgeFilteredImage(depth32F, output32F);// 将结果转换回8位图像以便显示output32F.convertTo(output, CV_16UC1, 255.0);}void depthToPointCloud(const cv::Mat& depth_img, const cv::Mat& rgb_img, pcl::PointCloud<pcl::PointXYZRGB>& cloud) {// 假设 fx, fy, cx, cy 是相机内参float fx = 644.7825927734375; // 焦距xfloat fy = 644.0340576171875; // 焦距yfloat cx = 636.1322631835938; // 主点xfloat cy = 367.4698486328125; // 主点ycloud.width = depth_img.cols;cloud.height = depth_img.rows;cloud.is_dense = false;cloud.points.resize(cloud.width * cloud.height);cloud.header.frame_id = "map";for (int v = 0; v < depth_img.rows; v++) {for (int u = 0; u < depth_img.cols; u++) {pcl::PointXYZRGB& point = cloud.points[v * depth_img.cols + u];float depth = depth_img.at<ushort>(v, u) / 1000.0f; // 深度单位转换为米if (depth == 0) continue; // 无效点跳过// 从像素坐标转换到相机坐标系point.x = (u - cx) * depth / fx;point.y = (v - cy) * depth / fy;point.z = depth;// 设置颜色cv::Vec3b rgb = rgb_img.at<cv::Vec3b>(v, u);uint32_t rgb_val = ((uint32_t)rgb[0] << 16 | (uint32_t)rgb[1] << 8 | (uint32_t)rgb[2]);point.rgb = *reinterpret_cast<float*>(&rgb_val);}}}private:ros::NodeHandle nh_;image_transport::ImageTransport it_;image_transport::Publisher pub_;message_filters::Subscriber<sensor_msgs::Image> image_sub_, depth_sub_;boost::shared_ptr<message_filters::Synchronizer<message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image>>> sync_;ros::Publisher cloud_pub_;ros::Publisher cloud2_pub_;
};int main(int argc, char** argv)
{ros::init(argc, argv, "image_processor");ImageProcessor ip;ros::spin();return 0;
}

这里FBS和其他的滤波器的本质区别是,FBS引入了信心图(confidence),这使得其在进行滤波时不会被无效像素所影响,因此我建议,当使用无信心图的滤波器时,尽量使用其他后处理方法填充空洞,减少无效像素;当使用FBS时,建议深度图宁缺毋滥,尽量保持真值。

2 效果展示

这是realsense D455的原始深度图与经过FBS的深度图是对比。

nullrawFBS
深度图请添加图片描述请添加图片描述
深度图请添加图片描述请添加图片描述
点云在这里插入图片描述在这里插入图片描述

看起来似乎不错,但我们将其转换为点云就会发现,原始深度图干干净净,不同深度处的物体分离性很好;但是经过优化的深度图产生了大量的离群点,这些是FBS“猜”错的点。
请添加图片描述
这个视角下我们看到,FBS确实补全了部分缺失的深度值,但也带来了很大问题,最主要的问题就是这些错误的点。

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

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

相关文章

机器人路径规划:基于双向A*算法(bidirectional a star)的机器人路径规划(提供Python代码)

一、双向A*算法简介 传统A*算法是一种静态路网中求解最短路径最有效的方法&#xff0c; 它结合了BFS 算法和迪杰斯特拉算法(Dijkstra)的优点。 和迪杰斯特拉算法(Dijkstra)一样&#xff0c; A*算法能够用于 搜索最短路径&#xff1b; 和BFS 算法一样&#xff0c; A*算法可以用…

java:java.util.BitSet对象的Fastjson序列化和反序列化实现

java.util.BitSet是个非常方便的比特位数据存储和操作类&#xff0c;一个 bit 具有2个值&#xff1a;0和1&#xff0c;正好可以用来表示 false 和 true&#xff0c;适用于判断“数据是否存在”的场景。 但是&#xff0c;这个从JDK1.0版本就存在的类&#xff0c;Jackson,Fastjso…

JavaScript 箭头函数

1.什么是箭头函数 箭头函数是ES6新定义函数的语法  语法&#xff1a;(参数)>函数体 传统函数&#xff1a; let sum function(a,b){return ab;} 箭头函数 let sum(a,b)>{return ab;} 2.箭头函数的用法 2.1省略保函参数的小括号 如果只有一个参数&#xff0c;参数小括号…

【JavaScript】NPM常用指令指南

河水清清弯又长 姑娘水边浣霓裳 清风卷过白云旁 飞鸟载来春花香 河水清清弯又长 姑娘水边浣霓裳 清风卷过白云旁 朝霞换夕阳 重逢是梦乡 春潮悠悠送波浪 石桥湾下小舟荡 此去经年谁如常 难得人间笑一场 春潮悠悠送波浪 石桥湾下小舟荡 此去经年谁如常 故人心头上 地久天又长 …

Word文档密码设置:Python设置、更改及移除Word文档密码

给Word文档设置打开密码是常见的Word文档加密方式。为Word文档设置打开密码后&#xff0c;在打开该文档时&#xff0c;需要输入密码才能预览及编辑&#xff0c;为Word文档中的信息提供了有力的安全保障。如果我们需要对大量的Word文档进行加密、解密处理&#xff0c;Python是一…

1. Java基础入门

1. Java基础入门 1.1 Java介绍(了解) 1.1.1 Java背景 Java是美国 sun 公司&#xff08;Stanford University Network&#xff09;在1995年推出的一门计算机高级编程语言。Java 之父&#xff1a;詹姆斯高斯林(James Gosling)。 2009年 sun公司被Oracle公司收购。Java公司图标…

大数据面试题 —— Zookeeper

目录 ZooKeeper 的定义ZooKeeper 的特点ZooKeeper 的应用场景你觉得Zookeeper比较重要的功能ZooKeeper 的选举机制 ***zookeeper主节点故障&#xff0c;如何重新选举&#xff1f;ZooKeeper 的监听原理 ***zookeeper集群的节点数为什么建议奇数台 ***ZooKeeper 的部署方式有哪几…

JAVA 栈和队列总结

除了最底层下面三个是实现类&#xff0c;其他都是接口。 双端队列&#xff08;队头队尾都可以插入和删除元素&#xff09;的方法&#xff1a; 普通队列方法&#xff1a; 常用的是add(),poll(), element() 我们用Deque(双端队列)实现栈 Deque当栈用的时候的方法。 deque.push…

利用WebGL绘制简单几何

利用WebGL绘制最简单的几何图形 一、WebGL简介 WebGL是一种用于在网页上渲染交互式3D和2D图形的JavaScript API。它基于OpenGL ES 2.0&#xff0c;提供了一种在浏览器中使用硬件加速图形的方式。 二、图形系统绘图流程 图形系统的通用绘图流程会包括六个部分&#xff1a; …

2024年【电工(初级)】考试内容及电工(初级)证考试

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 2024年【电工&#xff08;初级&#xff09;】考试内容及电工&#xff08;初级&#xff09;证考试&#xff0c;包含电工&#xff08;初级&#xff09;考试内容答案和解析及电工&#xff08;初级&#xff09;证考试练习…

C++中的类模板

C中的类模板 类模板 类模板在C中是一种非常强大的工具&#xff0c;它允许程序员编写与数据类型无关的代码。简单来说&#xff0c;类模板允许你定义一个蓝图&#xff0c;这个蓝图可以用来生成具体类型的类。使用类模板可以提高代码的复用性&#xff0c;减少重复代码&#xff0…

字节跳动春招研发部分编程题汇总做题笔记---Java

3.雀魂启动&#xff01; 小包最近迷上了一款叫做雀魂的麻将游戏&#xff0c;但是这个游戏规则太复杂&#xff0c;小包玩了几个月了还是输多赢少。 于是生气的小包根据游戏简化了一下规则发明了一种新的麻将&#xff0c;只留下一种花色&#xff0c;并且去除了一些特殊和牌方式&…

Java基础知识总结(14)

map集合 /* java.util.Map接口中常用的方法 1、Map和Collection 没有继承关系 2、Map集合以key和value的方式存储数据&#xff1a;键值对key和valuea都是引用数据类型key和value都是存储对象的内存地址key起到主导地位&#xff0c;value是key的一个附属品 3、Map接口中常用的方…

GDAL实现大幅影像的快速读取

这里做个备份&#xff0c;原文链接 遥感影像小则几百兆&#xff0c;大则5,6GB&#xff0c;所以在使用GDAL进行图像读取时面临读写速度较慢的问题&#xff0c;我们可以深入研究gdal中RasterIO函数的机制&#xff0c;发现该函数是通过一行一行读取影像来实现影像读入内存的&…

【教学类-40-01】20240322 幼儿视力检查照片合成GIF

作品展示——GIF动图 背景需求&#xff1a; 2024年3月22日&#xff0c;中班幼儿视力检查&#xff0c;保健老师表扬我们班幼儿视力正常率高。 我为每位孩子拍照时&#xff0c;突然想把动作图用Python变成GIF图片&#xff0c;于是每位孩子都拍了多张“辨认视力表的不同手势”&a…

基于Springboot的西安旅游系统(有报告)。Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的西安旅游系统&#xff08;有报告&#xff09;。Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系结构&…

动态规划(算法竞赛、蓝桥杯)--单调队列优化绿色通道

1、B站视频链接&#xff1a;E45 单调队列优化DP 绿色通道_哔哩哔哩_bilibili #include <bits/stdc.h> using namespace std; const int N5e410; int n,tim,w[N],f[N],q[N];bool check(int m){int h1,t0;for(int i1; i<n; i){while(h<t && f[q[t]]>f[i-…

visual studio卸载几种方法

1、控制面板卸载&#xff1b; 2、有时候会发现控制面板卸载会失败&#xff0c;无法卸载&#xff0c;这时候要先把下面目录的关于visual studio的都删除&#xff0c;然后重启电脑后&#xff0c;重新安装vs即可。

使用echart绘制拓扑图,树类型,自定义tooltip和label样式,可收缩

效果如图&#xff1a; 鼠标移上显示 vue3 - ts文件 “echarts”: “^5.4.3”, import { EChartsOption } from echarts import * as echarts from echarts/core import { TooltipComponent } from echarts/components import { TreeChart } from echarts/charts import { C…

复试专业前沿问题问答合集10-1——区块链与加密货币

复试专业前沿问题问答合集10-1——区块链与加密货币 区块链与加密货币安全以及6G通信的基础知识问答: 区块链以及加密货币相关的基础安全知识 包括区块链如何确保交易安全、共识机制的作用、加密货币钱包的保护措施、智能合约的工作原理以及如何防范潜在的网络攻击。这些知…