import pyrealsense2 as rs
import cv2 as cv
import numpy as nppipeline = 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)# 设定需要对齐的方式(这里是深度对齐彩色,彩色图不变,深度图变换)
align_to = rs.stream.color
# 设定需要对齐的方式(这里是彩色对齐深度,深度图不变,彩色图变换)
# align_to = rs.stream.depthalignedFs = rs.align(align_to)profile = pipeline.start(cfg)try:while True:fs = pipeline.wait_for_frames()aligned_frames = alignedFs.process(fs)color_frame = aligned_frames.get_color_frame()depth_frame = aligned_frames.get_depth_frame()if not depth_frame or not color_frame:continuecolor_image = np.asanyarray(color_frame.get_data())depth_image = np.asanyarray(depth_frame.get_data())# D·C 191122:打印depth_image的最大值看看# print(depth_image.max())# 可以看到,最大的数值从一万到六万不等(表示最远距离十多米到六十米这样)# D·C 191122:打印数据类型看看# print(depth_image.dtype)# uint16# print(color_image.dtype)# uint8# D·C 191122:打印color_image的维度看看# print(color_image.shape)# (480, 640, 3)# print(depth_image.shape)# (480, 640)# D·C 191122:打印cv.convertScaleAbs(depth_image, alpha=0.03)的数据类型和维度看看:# print(cv.convertScaleAbs(depth_image, alpha=0.03).dtype)# uint8# print(cv.convertScaleAbs(depth_image, alpha=0.03).shape)# (480, 640)# D·C 191122:打印cv.applyColorMap(cv.convertScaleAbs(depth_image, alpha=0.03), cv.COLORMAP_JET)的数据类型和维度看看# print(cv.applyColorMap(cv.convertScaleAbs(depth_image, alpha=0.03), cv.COLORMAP_JET).dtype)# uint8# print(cv.applyColorMap(cv.convertScaleAbs(depth_image, alpha=0.03), cv.COLORMAP_JET).shape)# (480, 640, 3)# D·C 191122:打印cv.convertScaleAbs(depth_image, alpha=0.03)的最大值看看# print(cv.convertScaleAbs(depth_image, alpha=0.03))# 可看到最大值为255# 估计若原值*alpha大于255,则将其取值为255,而当alpha为0.03时,能够映射的最大可变距离为255/0.03=8500mm=8.5m# D·C 191122:修改alpha参数后,发现图像对比度发生变化(比如alpha=1,图像基本呈红没啥对比度、alpha=0.001,图像呈蓝也没啥对比度、alpha=1点几,效果也不行)# origin:depth_image = cv.applyColorMap(cv.convertScaleAbs(depth_image, alpha=0.03), cv.COLORMAP_JET)depth_image = cv.applyColorMap(cv.convertScaleAbs(depth_image, alpha=0.03), cv.COLORMAP_JET)images = np.hstack((color_image, depth_image))# window = cv.namedWindow('window', cv.WINDOW_AUTOSIZE)cv.imshow('window', images)cv.waitKey(1)
finally:pipeline.stop()

对齐原理

The term “alignment” w.r.t SDK denotes a synthetic image generation with the help of depth map. In the process a new image is created using triangulation method comprising of 2D=>3D=>2D transformations.
The transformation is akin to a ray tracing - each pixel is first “fired” from 2D to 3D space, and then projected into the 2D plane of another sensor.
So by definition the aligned data is generated from depth in conjunction with color/ir data, hence the areas with no depth data coverage result in “holes” in the generated image.
The above serves a specific purpose - allowing 1:1 mapping of depth to color and vice versa. So when a user selects RGB pixel of interest then the SDK will be able to provide the corresponding Depth deterministically with no false positives.
This is a critical feature in scenarios where the depth is essentially used as a validation filter for other sensors - collision avoidance, segmentation, object recognition.
While using sheer 2D image manipulations would similarly allow to recalculate an image from a different point of view, it would also introduce fundamental flaws - preserve the pixels for which there is no corresponding depth data, and also introduce artifacts due to occlusion and different perspective, which would undermine the declared purpose.
Eventually there are more than one way to “align” images, depending of the use-case requirements. And the above explanation highlights the specific advantage (and also the utility) of the method implemented by the SDK.

SDK中的“对齐”一词表示借助深度图生成的合成图像。在此过程中,将使用由2D => 3D => 2D转换组成的三角测量方法来创建新图像。
转换类似于ray tracing-每个像素首先从2D空间“发射”到3D空间,然后投影到另一个传感器的2D平面中。
因此,根据定义,对齐的数据是结合颜色/ ir数据从深度生成的,因此没有深度数据覆盖的区域会在生成的图像中产生“孔”。

上面的内容用于特定目的-
允许将深度与颜色进行1:1映射,反之亦然。因此,当用户选择感兴趣的RGB像素时,SDK将能够确定性地提供相应的深度,而不会产生误报。
这在深度实际上用作其他传感器的验证过滤器(避免碰撞,分割,物体识别)的情况下是至关重要的功能。

虽然使用纯粹的2D图像处理可以类似地从不同的角度重新计算图像,但它也会带来基本的缺陷-保留没有相应深度数据的像素,并且还会由于遮挡和视角不同而引入伪像,这会破坏宣布的目的。

最终,取决于用例需求,有不止一种“对齐”图像的方法。上面的说明着重介绍了由SDK实现的方法的特定优势(以及实用程序)。

参考文章:Align to Depth produces lossy color image #5030

Intel RealsenseD435 color图与depth图的两种对齐(align)方式相关推荐

  1. swiper 定义放多少张图片,小程序swiper轮播图,自定义样式,两种方法:原生方法和bindchange方法;将点点改为数字(当前第几张 /总共几张);点击点点跳转当前图片...

    一.点点部分 1.1.通过原生方法 (1)wxml文件 (2)wxss /* 轮播图部分 */ .swiperBar { width: 690rpx; height: 337rpx; margin: ...

  2. java 获取gif帧数_Java图片处理之获取gif图一帧图片的两种方法

    前言 本文主要给大家介绍了关于Java获取gif图一帧图片的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧. 一.Java原生代码实现gif获取一帧图片 先看测试代码: pu ...

  3. Prometheus核心概念:一图了解Counter和Gauge两种数据指标类型的区别

    目录 1 背景 2 何为Counter类型? 2.1 Counter定义 3 何为Gauge类型? 3.1 Gauge定义 4 Counter和Gauge的对比 1 背景 Prometheus整体架构 ...

  4. 有向无环图(DAG)拓扑排序的两种方法

    如下图的DAG: 第一种: (1)从AOV网中选择一个没有前驱的顶点并且输出它: (2)从AOV网中删除该顶点,并且上去所有该顶点为尾的弧: (3)重复上述两步,直到全部顶点都被输出,或者AOV网中不 ...

  5. JS制作字体图(文字图)

    我们经常会在网页中看到很多小图标,其实这些图标大多数都不是图片,而是字体图. 制作字体图总共有三种办法: 第一种: CSS Sprite(美其名曰雪碧图) 第二种: font + HTML 进行制作 ...

  6. python matplotlib绘图大全(散点图、柱状图、饼图、极坐标图、热量图、三维图以及热图)...

    //2019.7.14晚 matplotlib七种常见图像输出编程大全 七种图形汇总输出如下: import numpy as np #导入数据结构nmupy模块 import matplotlib. ...

  7. 彩色图、灰度图和二值图

    首先计算机中图像是用矩阵存储的,所以在分析图像时,应当用矩阵的眼光来看待 1.RGB模式(百万种颜色) 2.CMYK模式(四种印刷色) 3.索引模式(256种颜色) 4.灰度模式(256级灰度) 5. ...

  8. 图机器学习——5.9 图神经网络:图的增广

    由于在实际的训练中,原始的图结构往往不是训练的最优图结构.下面我们考虑如何对图进行增强(graph augmentation),这个类似于数据扩增,提升训练效率,模型的泛化能力及测试集的准确率. 这种 ...

  9. UML图之五——时序图

    一.什么是时序图 序列图表示了系统在参与者互动执行某一个用例期间,系统内部的一群对象的协作情况.一个用例就对应一个时序图.序列图是对系统动态行为进行描述.用于用例分析和设计阶段. 二.对比 1.序列图 ...

最新文章

  1. 做ML项目,任务繁多琐碎怎么办?这份自查清单帮你理清思路
  2. 基于数据库数据增量同步_基于canal实现分布式数据同步
  3. CSS3系列一(概述、选择器、使用选择器插入内容)
  4. 计算机d盘无法格式化,电脑D盘无法格式化怎么办 D盘无法格式化问题解决办法...
  5. Angular应用里的tsconfig.app.json
  6. MySQL 大表优化方案(1)
  7. Linux系统编程----8(竞态条件,时序竞态,pause函数,如何解决时序竞态)
  8. ajax jsp模糊查询源码,ajax模糊查询api
  9. 微软开启imap服务器,连接到 IMAP 或 SMTP 服务器
  10. 合并excel方法汇总
  11. nagios监控系统环境部署安装(LAMP环境)
  12. dns被劫持怎么办、如何完美解决网站DNS域名被劫持
  13. 5GHz WIFI DFS测试介绍
  14. linux内核和发行版本的关系,简述Linux内核和Linux发行版的区别
  15. 多重背包的二进制拆分法
  16. 化工厂人员定位应考虑哪些因素?
  17. Unity-业余2D游戏制作笔记02-Dialogue System for Unity使用
  18. 智能暖风机——6.利用TM1650实现显示功能
  19. 软件质量保证与测试技术实验报告(三)静态测试
  20. Centos7 Jenkins 下载安装-----看此文章即可

热门文章

  1. 如歌将两个数组合并_腾讯50题---合并两个有序数组
  2. 【重复制造精讲】3、成本收集
  3. smartform连续打印,并自动补充空行
  4. FI模块组织机构配置文档
  5. 云技术与云计算的区别
  6. CAN'T TAKE MY EYES OF YOU
  7. abap 调用外部web service 使用小结
  8. 电商ERP vs.传统ERP,有何不一样?
  9. 导出SAP表结构到EXCEl
  10. 永洪Desktop一个工具就可搞定中国式复杂报表需求