Intel Realsense d435 使用python对深度图进行预处理_our implementation of temporal filter does basic t-程序员宅基地

技术标签: 深度图  过滤器  python  Intel Realsense  intel Realsense  

Intel Realsense d435 使用python对深度图进行预处理

本文中主要翻译一下一篇关于深度图预处理过滤器的内容,后面还会有关于距离测量的。
原文中的图像显示,是使用matplotlib.pyplot工具,在本文中,使用opencv来显示深度图》
首先常规操作导入包:

import cv2
import numpy as np
import pyrealsense2 as rs

获取我们所需要的图像,通过摄像头或者本地都可以

pipe = rs.pipeline()
cfg = rs.config()
cfg.enable_stream(rs.stream.depth,640,480,rs.format.z16,30)
cfg.enable_stream(rs.stream.color,640,480,rs.format.bgr8,30)
profile = pipe.start(cfg)

try:
    while True:
        frame = pipe.wait_for_frames()
        depth_frame = frame.get_depth_frame()
        print('capture success')
        if cv2.waitKey(10)&0xff == ord('q'):
            break

finally:
    pipe.stop()

获取成功,在终端打印信息

一、深度图像的可视化

使用pyrealsense2库中提供的colorizer来将图像中的深度值转为可以显示的形式:

colorizer = rs.colorizer()
colorizer_depth = np.asanyarray(colorizer.colorize(depth_frame).get_data())
cv2.imshow('colorizer depth',colorizer_depth)

在这里插入图片描述

二、应用过滤器

(1)抽取(Decimation)

When using Depth-from-Stereo solution, z-accuracy is related to original spacial resolution.
If you are satisfied with lower spatial resolution, the Decimation Filter will reduce spatial resolution preserving z-accuracy and performing some rudamentary hole-filling.
这段话的意思就是类似与图像处理中的降采样,图像的分辨率会降低(640x480----->320x240),但会讲一些黑色的空洞进行填充。

 		#二、抽取Decimation
        colorizer = rs.colorizer()
        decimation = rs.decimation_filter()
        decimationed_depth = decimation.process(depth_frame)
        colorized_depth = np.asanyarray(colorizer.colorize(decimationed_depth).get_data())
        cv2.imshow('decimationed depth',colorized_depth)

        #可以设置参数类似于迭代次数
        decimation.set_option(rs.option.filter_magnitude,4)
        decimationed_depth = decimation.process(depth_frame)
        colorized_depth = np.asanyarray(colorizer.colorize(decimationed_depth).get_data())
        cv2.imshow('decimationed4 depth',colorized_depth)

在这里插入图片描述

(2)空间过滤器(Spatial Filter)

空间滤波器的论文:
Domain Transform for Edge-Aware Image and Video Processing

#三、空间滤波器(spatial filter)
        colorizer = rs.colorizer()
        spatial = rs.spatial_filter()
        filtered_depth = spatial.process(depth_frame)
        colorized_depth = np.asanyarray(colorizer.colorize(filtered_depth).get_data())
        cv2.imshow('filtered depth',colorized_depth)

        # 可以设置相关的参数
        spatial.set_option(rs.option.filter_magnitude,5)
        spatial.set_option(rs.option.filter_smooth_alpha,1)
        spatial.set_option(rs.option.filter_smooth_delta,50)
        filtered_depth = spatial.process(depth_frame)
        colorized_depth = np.asanyarray(colorizer.colorize(filtered_depth).get_data())
        cv2.imshow('filtered1 depth',colorized_depth)

在这里插入图片描述同时,spatial也提供了一个基本的空洞填充操作:

 		spatial.set_option(rs.option.holes_fill,3)
        filtered_depth = spatial.process(depth_frame)
        colorized_depth = np.asanyarray(colorizer.colorize(filtered_depth).get_data())
        cv2.imshow('fill hole',colorized_depth)

在这里插入图片描述

(3)时间过滤器(Temporal Filter)

Our implementation of Temporal Filter does basic temporal smoothing and hole-filling. It is meaningless when applied to a single frame, so let’s capture several consecutive frames:
我们对“时间过滤器”的实现实现了基本的时间平滑和孔填充。 当应用于单个帧时它是没有意义的,因此让我们捕获几个连续的帧:

 #四、时间滤波器(Temporal Filter)
        colorizer = rs.colorizer()
        
        frames.append(depth_frame)
        i += 1
        if i == 10:
            i = 0
            temporal = rs.temporal_filter()
            print(len(frames))
            for x in range(10):
                temp_filtered = temporal.process(frames[x])
            frames = []
            colorized_depth = np.asanyarray(colorizer.colorize(temp_filtered).get_data())
            cv2.imshow('temporal depth',colorized_depth)

在这里插入图片描述

(4)孔填充(Hole Filling)

Hole Filling filter offers additional layer of depth exterpolation:
孔填充过滤器提供了深度外推的附加层:

#五、孔填充(Hole Filling)
        colorizer = rs.colorizer()
        hole_filling = rs.hole_filling_filter()
        filled_depth = hole_filling.process(depth_frame)
        colorized_depth = np.asanyarray(colorizer.colorize(filled_depth).get_data())
        cv2.imshow('filled depth',colorized_depth)

在这里插入图片描述

(5)放在一起(Putting Everything Together)

These filters work best when applied sequentially one after another. At longer range, it also helps using disparity_transform to switch from depth representation to disparity form:
依次顺序应用这些过滤器时,效果最佳。 在更大范围内,它还有助于使用disparity_transform从深度表示转换为视差形式:

#六、复合多个滤波器
        colorizer = rs.colorizer()        
        depth_to_disparity = rs.disparity_transform(True)
        disparity_to_depth = rs.disparity_transform(False)

        decimation = rs.decimation_filter()
        spatial = rs.spatial_filter()
        temporal = rs.temporal_filter()
        hole_filling = rs.hole_filling_filter()


        frames.append(depth_frame)
        i += 1
        if i == 10:
            i = 0
            for x in range(10):
                frame = frames[x]
                frame = decimation.process(frame)
                frame = depth_to_disparity.process(frame)
                frame = spatial.process(frame)
                frame = temporal.process(frame)
                frame = disparity_to_depth.process(frame)
                frame = hole_filling.process(frame)
            frames = []
            colorized_depth = np.asanyarray(colorizer.colorize(frame).get_data())
            cv2.imshow('more depth filter',colorized_depth)

在这里插入图片描述

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_25105061/article/details/111312298

智能推荐

JavaScript学习笔记_curry函数未定义-程序员宅基地

文章浏览阅读343次。五种原始的变量类型1.Undefined--未定义类型 例:var v;2.String -- ' '或" "3.Boolean4.Number5.Null--空类型 例: var v=null;Number中:NaN -- not a number非数本身是一个数字,但是它和任何数字都不相等,代表非数,它和自己都不相等判断是不是NaN不能用=_curry函数未定义

兑换码编码方案实践_优惠券编码规则-程序员宅基地

文章浏览阅读1.2w次,点赞2次,收藏17次。兑换码编码设计当前各个业务系统,只要涉及到产品销售,就离不开大大小小的运营活动需求,其中最普遍的就是兑换码需求,无论是线下活动或者是线上活动,都能起到良好的宣传效果。兑换码:由一系列字符组成,每一个兑换码对应系统中的一组信息,可以是优惠信息(优惠券),也可以是相关奖品信息。在实际的运营活动中,要求兑换码是唯一的,每一个兑换码对应一个优惠信息,而且需求量往往比较大(实际上的需求只有预期_优惠券编码规则

c语言周林答案,C语言程序设计实训教程教学课件作者周林ch04结构化程序设计课件.ppt...-程序员宅基地

文章浏览阅读45次。C语言程序设计实训教程教学课件作者周林ch04结构化程序设计课件.ppt* * 4.1 选择结构程序设计 4.2 循环结构程序设计 4.3 辅助控制语句 第四章 结构化程序设计 4.1 选择结构程序设计 在现实生活中,需要进行判断和选择的情况是很多的: 如果你在家,我去拜访你 如果考试不及格,要补考 如果遇到红灯,要停车等待 第四章 结构化程序设计 在现实生活中,需要进行判断和选择的情况..._在现实生活中遇到过条件判断的问

幻数使用说明_ioctl-number.txt幻数说明-程序员宅基地

文章浏览阅读999次。幻数使用说明 在驱动程序中实现的ioctl函数体内,实际上是有一个switch{case}结构,每一个case对应一个命令码,做出一些相应的操作。怎么实现这些操作,这是每一个程序员自己的事情。 因为设备都是特定的,这里也没法说。关键在于怎样组织命令码,因为在ioctl中命令码是唯一联系用户程序命令和驱动程序支持的途径 。 命令码的组织是有一些讲究的,因为我们一定要做到命令和设备是一一对应的,利_ioctl-number.txt幻数说明

ORB-SLAM3 + VScode:检测到 #include 错误。请更新 includePath。已为此翻译单元禁用波浪曲线_orb-slam3 include <system.h> 报错-程序员宅基地

文章浏览阅读399次。键盘按下“Shift+Ctrl+p” 输入: C++Configurations,选择JSON界面做如下改动:1.首先把 “/usr/include”,放在最前2.查看C++路径,终端输入gcc -v -E -x c++ - /usr/include/c++/5 /usr/include/x86_64-linux-gnu/c++/5 /usr/include/c++/5/backward /usr/lib/gcc/x86_64-linux-gnu/5/include /usr/local/_orb-slam3 include 报错

「Sqlserver」数据分析师有理由爱Sqlserver之十-Sqlserver自动化篇-程序员宅基地

文章浏览阅读129次。本系列的最后一篇,因未有精力写更多的入门教程,上篇已经抛出书单,有兴趣的朋友可阅读好书来成长,此系列主讲有理由爱Sqlserver的论证性文章,希望读者们看完后,可自行做出判断,Sqlserver是否真的合适自己,目的已达成。渴望自动化及使用场景笔者所最能接触到的群体为Excel、PowerBI用户群体,在Excel中,我们知道可以使用VBA、VSTO来给Excel带来自动化操作..._sqlsever 数据分析

随便推点

智慧校园智慧教育大数据平台(教育大脑)项目建设方案PPT_高校智慧大脑-程序员宅基地

文章浏览阅读294次,点赞6次,收藏4次。教育智脑)建立学校的全连接中台,对学校运营过程中的数据进行处理和标准化管理,挖掘数据的价值。能:一、原先孤立的系统聚合到一个统一的平台,实现单点登录,统一身份认证,方便管理;三、数据共享,盘活了教育大数据资源,通过对外提供数。的方式构建教育的通用服务能力平台,支撑教育核心服务能力的沉淀和共享。物联网将学校的各要素(人、机、料、法、环、测)全面互联,数据实时。智慧校园解决方案,赋能教学、管理和服务升级,智慧教育体系,该数据平台具有以下几大功。教育大数据平台底座:教育智脑。教育大数据平台,以中国联通。_高校智慧大脑

编程5大算法总结--概念加实例_算法概念实例-程序员宅基地

文章浏览阅读9.5k次,点赞2次,收藏27次。分治法,动态规划法,贪心算法这三者之间有类似之处,比如都需要将问题划分为一个个子问题,然后通过解决这些子问题来解决最终问题。但其实这三者之间的区别还是蛮大的。贪心是则可看成是链式结构回溯和分支界限为穷举式的搜索,其思想的差异是深度优先和广度优先一:分治算法一、基本概念在计算机科学中,分治法是一种很重要的算法。字面上的解释是“分而治之”,就是把一个复杂的问题分成两_算法概念实例

随笔—醒悟篇之考研调剂_考研调剂抑郁-程序员宅基地

文章浏览阅读5.6k次。考研篇emmmmm,这是我随笔篇章的第二更,原本计划是在中秋放假期间写好的,但是放假的时候被安排写一下单例模式,做了俩机试题目,还刷了下PAT的东西,emmmmm,最主要的还是因为我浪的很开心,没空出时间来写写东西。  距离我考研结束已经快两年了,距离今年的考研还有90天左右。  趁着这个机会回忆一下青春,这一篇会写的比较有趣,好玩,纯粹是为了记录一下当年考研中发生的有趣的事。  首先介绍..._考研调剂抑郁

SpringMVC_class org.springframework.web.filter.characterenco-程序员宅基地

文章浏览阅读438次。SpringMVC文章目录SpringMVC1、SpringMVC简介1.1 什么是MVC1.2 什么是SpringMVC1.3 SpringMVC的特点2、HelloWorld2.1 开发环境2.2 创建maven工程a>添加web模块b>打包方式:warc>引入依赖2.3 配置web.xml2.4 创建请求控制器2.5 创建SpringMVC的配置文件2.6 测试Helloworld2.7 总结3、@RequestMapping注解3.1 @RequestMapping注解的功能3._class org.springframework.web.filter.characterencodingfilter is not a jakart

gdb: Don‘t know how to run. Try “help target“._don't know how to run. try "help target".-程序员宅基地

文章浏览阅读4.9k次。gdb 远程调试的一个问题:Don't know how to run. Try "help target".它在抱怨不知道怎么跑,目标是什么. 你需要为它指定target remote 或target extended-remote例如:target extended-remote 192.168.1.136:1234指明target 是某IP的某端口完整示例如下:targ..._don't know how to run. try "help target".

c语言程序设计教程 郭浩志,C语言程序设计教程答案杨路明郭浩志-程序员宅基地

文章浏览阅读85次。习题 11、算法描述主要是用两种基本方法:第一是自然语言描述,第二是使用专用工具进行算法描述2、c 语言程序的结构如下:1、c 语言程序由函数组成,每个程序必须具有一个 main 函数作为程序的主控函数。2、“/*“与“*/“之间的内容构成 c 语言程序的注释部分。3、用预处理命令#include 可以包含有关文件的信息。4、大小写字母在 c 语言中是有区别的。5、除 main 函数和标准库函数以..._c语言语法0x1e