立体匹配算法(Stereo correspondence)

SGM(Semi-Global Matching)原理:

SGM的原理在wiki百科和matlab官网上有比较详细的解释:
wiki matlab
如果想完全了解原理还是建议看原论文 paper(我就不看了,懒癌犯了。)
优质论文解读和代码实现
一位大神自己用c++实现的SGM算法github
先介绍两个重要的参数:
注:这一部分参考的是matlab的解释,后面的部分是参考的opencv的实现,细节可能有些出入,大体上是一致的。
Disparity Levels and Number of Directions

Disparity Levels

Disparity Levels: Disparity levels is a parameter used to define the search space for matching. As shown in figure below, the algorithm searches for each pixel in the Left Image from among D pixels in the Right Image. The D values generated are D disparity levels for a pixel in Left Image. The first D columns of Left Image are unused because the corresponding pixels in Right Image are not available for comparison. In the figure, w represents the width of the image and h is the height of the image. For a given image resolution, increasing the disparity level reduces the minimum distance to detect depth. Increasing the disparity level also increases the computation load of the algorithm. At a given disparity level, increasing the image resolution increases the minimum distance to detect depth. Increasing the image resolution also increases the accuracy of depth estimation. The number of disparity levels are proportional to the input image resolution for detection of objects at the same depth. This example supports disparity levels from 8 to 128 (both values inclusive). The explanation of the algorithm refers to 64 disparity levels. The models provided in this example can accept input images of any resolution.——matlab

字太多,看不懂,让gpt解释了一下:

# gpt生成,仅供本人理解SSD原理
import numpy as npdef compute_disparity(left_img, right_img, block_size=5, num_disparities=64):# 图像尺寸height, width = left_img.shape# 初始化视差图disparity_map = np.zeros_like(left_img)# 遍历每个像素for y in range(height):for x in range(width):# 定义搜索范围min_x = max(0, x - num_disparities // 2)max_x = min(width, x + num_disparities // 2)# 提取左图像块left_block = left_img[y:y+block_size, x:x+block_size]# 初始化最小 SSD 和对应的视差min_ssd = float('inf')best_disparity = 0# 在搜索范围内寻找最佳视差for d in range(min_x, max_x):# 提取右图像块right_block = right_img[y:y+block_size, d:d+block_size]# 计算 SSDssd = np.sum((left_block - right_block)**2)# 更新最小 SSD 和对应的视差if ssd < min_ssd:min_ssd = ssdbest_disparity = abs(x - d)# 将最佳视差保存到视差图中disparity_map[y, x] = best_disparityreturn disparity_map# 示例用法
left_img = np.random.randint(0, 255, size=(100, 100), dtype=np.uint8)
right_img = np.roll(left_img, shift=5, axis=1)  # 创建右图,右移了5个像素disparity_map = compute_disparity(left_img, right_img, block_size=5, num_disparities=64)# 可视化结果(这里简化为将视差图缩放以便可视化)
import matplotlib.pyplot as plt
plt.imshow(disparity_map, cmap='gray')
plt.title('Disparity Map')
plt.show()

这样就明白了,Disparity Levels就是计算视差的范围(视差搜索范围)。

Number of Directions

Number of Directions:

Number of Directions: In the SGBM algorithm, to optimize the cost function, the input image is considered from multiple directions. In general, accuracy of disparity result improves with increase in number of directions. This example analyzes five directions: left-to-right (A1), top-left-to-bottom-right (A2), top-to-bottom (A3), top-right-to-bottom-left (A4), and right-to-left (A5).
在这里插入图片描述

按照单一路径匹配像素不够稳健,按照图像进行二维最优的全局匹配时间复杂度太高(NP完全问题),所以SGM的作者使用一维路径聚合的方式来近似二维最优。
在这里插入图片描述
pic 参考

SAD和SSD

用SAD 或者 SSD计算图像相似度,来做匹配。
公式:
> 这里是引用
公式和代码虽然是gpt生成的,但是公式看起来没错,代码可以帮助理解,仅供参考。
代码里面的 num_disparities 就是 Disparity Levels

SGBM in opencv

本人用opencv较多,这里仅关注代码在opencv的实现。

opencv StereoSGBM_create示例:

# gpt生成,仅作为参考,具体请查看opencv官方文档https://docs.opencv.org/4.x/d2/d85/classcv_1_1StereoSGBM.html
import cv2
import numpy as np# 读取左右视图
left_image = cv2.imread('left_image.png', cv2.IMREAD_GRAYSCALE)
right_image = cv2.imread('right_image.png', cv2.IMREAD_GRAYSCALE)# 创建SGBM对象
sgbm = cv2.StereoSGBM_create(minDisparity=0,numDisparities=16,  # 视差范围,一般为16的整数倍blockSize=5,        # 匹配块的大小,一般为奇数P1=8 * 3 * 5 ** 2,   # SGBM算法参数P2=32 * 3 * 5 ** 2,  # SGBM算法参数disp12MaxDiff=1,    # 左右视差图的最大差异uniquenessRatio=10,  # 匹配唯一性百分比speckleWindowSize=100,  # 过滤小连通区域的窗口大小speckleRange=32      # 连通区域内的差异阈值
)# 计算视差图
disparity_map = sgbm.compute(left_image, right_image)# 将视差图进行归一化处理
disparity_map = cv2.normalize(disparity_map, None, 0, 255, cv2.NORM_MINMAX)# 显示左图、右图和视差图
cv2.imshow('Left Image', left_image)
cv2.imshow('Right Image', right_image)
cv2.imshow('Disparity Map', disparity_map.astype(np.uint8))cv2.waitKey(0)
cv2.destroyAllWindows()

Difference between SGBM and SGM

what is the difference between opencv sgbm and sgm
opencv官方的解释:
The class implements the modified H. Hirschmuller algorithm [82] that differs from the original one as follows:

  1. By default, the algorithm is single-pass, which means that you consider only 5 directions instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the algorithm but beware that it may consume a lot of memory.
  2. The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the blocks to single pixels.
  3. Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi sub-pixel metric from [15] is used. Though, the color images are supported as well.
    Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness check, quadratic interpolation and speckle filtering).

大概的意思就是,与SGM不同之处在于,SGBM算法匹配的时候最小单位是blocks,而不是像素,不过设置blockSize=1的时候,就变成SGM了。没有实现互信息,而是用了更简单的Birchfield-Tomasi sub-pixel metric。除此之外还有一些预处理和后处理操作。
在这里插入图片描述
大概是这样,不知道对不对。

深度的立体匹配算法

先开个坑

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

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

相关文章

分析Java中的StringHelper类

目录 前言1. 概念2. 功能示例3. Demo示例 前言 在项目中实战学习并记录可用的工具类 1. 概念 Java标准库&#xff08;java.lang包&#xff09;并没有提供名为StringHelper的类。通常&#xff0c;类似的字符串处理工具类并不是Java标准库的一部分&#xff0c;而是由程序员自行…

python使用隐马尔可夫模型识别波形数据MFCC特征

python使用隐马尔可夫模型识别振动波形数据MFCC特征 1、简介 ​ 隐马尔可夫模型非常擅长对时间序列数据进行建模。 ​ 由于振动波形数据是时间序列信号,HMM能够满足波形分类需求。 ​ 隐马尔可夫模型是表示观察序列的概率分布的模型。假设输出是由隐藏状态生成的。 2、数…

如何在Windows安装Wnmp服务并实现固定地址远程访问

文章目录 前言1.Wnmp下载安装2.Wnmp设置3.安装cpolar内网穿透3.1 注册账号3.2 下载cpolar客户端3.3 登录cpolar web ui管理界面3.4 创建公网地址 4.固定公网地址访问 前言 WNMP是Windows系统下的绿色NginxMysqlPHP环境集成套件包&#xff0c;安装完成后即可得到一个Nginx MyS…

58.0/PhotoShop 图层的应用(详细版)

目录 58.1 图层的概念 58.2 图层的控制面板 58.3 图层的基本操作 58.3.1 新建图层 58.3.2 选择图层 58.3.3 复制图层 58.3.4 调整图层的叠加顺序 58.3.5 合并图层 58.4 图层样式 58.4.1 投影 58.4.2 内阴影 58.4.3 外发光样式 58.4.4 内发光样式 58.4.5 斜面和浮雕…

JSONyaml和Properties

注&#xff1a;取自GPT&#xff0c;总是忘记了&#xff0c;那我干脆就写一篇blog YAML&#xff08;YAML Ain’t Markup Language 或 YAML Ain’t a Markup Language&#xff09;和 JSON&#xff08;JavaScript Object Notation&#xff09;是两种不同的数据序列化格式&#xf…

程序员提问的艺术:28.4K Star指南,告别成为办公室讨厌鬼!

Github: https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way 原文&#xff1a;http://www.catb.org/~esr/faqs/smart-questions.html ✅为什么讨厌某些提问者 未自行尝试解决问题&#xff1a; ❌“怎么用Java写一个排序算法&#xff1f;” &#x1f44d;&#…

计算机毕业设计 基于SpringBoot的工作量统计系统的设计与实现 Java实战项目 附源码+文档+视频讲解

博主介绍&#xff1a;✌从事软件开发10年之余&#xff0c;专注于Java技术领域、Python人工智能及数据挖掘、小程序项目开发和Android项目开发等。CSDN、掘金、华为云、InfoQ、阿里云等平台优质作者✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精…

IDEA断点调试

IDEA断点调试 断点调试是一种在程序执行过程中暂停执行并逐步检查代码状态的方法。它允许开发者在程序运行到特定位置时暂停执行&#xff0c;查看变量的值、执行过程和调用栈等信息&#xff0c;从而更好地理解代码的运行情况和解决问题。可以帮助我们查看java底层源代码的执行…

day 57 算法训练|动态规划part17

参考&#xff1a;代码随想录 647. 回文子串 1. dp数组&#xff08;dp table&#xff09;以及下标的含义 是不是能找到一种递归关系&#xff0c;也就是判断一个子字符串&#xff08;字符串的下表范围[i,j]&#xff09;是否回文&#xff0c;依赖于&#xff0c;子字符串&#x…

Amos各版本安装指南

Amos下载链接 https://pan.baidu.com/s/1uyblN8Q-knNKkqQVlNnXTw?pwd0531 1.鼠标右击【Amos28】压缩包&#xff08;win11及以上系统需先点击“显示更多选项”&#xff09;选择【解压到 Amos28】。 2.打开解压后的文件夹&#xff0c;鼠标右击【Amos28】选择【以管理员身份运行…

基于SpringBoot的社区物资交易互助平台

文章目录 项目介绍主要功能截图:部分代码展示设计总结项目获取方式🍅 作者主页:超级无敌暴龙战士塔塔开 🍅 简介:Java领域优质创作者🏆、 简历模板、学习资料、面试题库【关注我,都给你】 🍅文末获取源码联系🍅 项目介绍 基于SpringBoot的社区物资交易互助平台,…

AUTOSAR软件架构描述文档,AUTOSAR_EXP_LayeredSoftwareArchitecture

AUTOSAR软件架构描述文档&#xff0c;我们常见的经典的CP架构及OS双核等架构描述 下载链接&#xff1a;https://www.autosar.org/fileadmin/standards/R21-11/CP/AUTOSAR_EXP_LayeredSoftwareArchitecture.pdf

macos下php 5.6 7.0 7.4 8.0 8.3 8.4全版本PHP开发环境安装方法

在macos中如果使用brew 官方默认的core tap 只可以安装官方最新的稳定版PHP, 如果想要安装 php 5.6 或者 php 8.4版本的PHP就需要使用第三方的tap , 这里分享一个比较全面的brew tap shivammathur/php 这个tap里面包含了从php5.6到最新版php8.4的所有可用最新版本PHP, 而且是同…

IDEA设置新建类注释、手动注释详解

文章目录 一、背景二、模板三、设置方法1、新建类注释设置2、手动注释设置 一、背景 每次在一台新电脑安装idea&#xff0c;都需要重新设置idea注释配置&#xff0c;说常用吧&#xff0c;也就新安装时才用&#xff0c;时间久步骤容易忘记&#xff0c;所以用此文章记录一下。 二…

阿里云服务器系统盘高效云盘、ESSD Entry云盘、SSD云盘、ESSD云盘测评

阿里云服务器系统盘或数据盘支持多种云盘类型&#xff0c;如高效云盘、ESSD Entry云盘、SSD云盘、ESSD云盘、ESSD PL-X云盘及ESSD AutoPL云盘等&#xff0c;阿里云百科aliyunbaike.com详细介绍不同云盘说明及单盘容量、最大/最小IOPS、最大/最小吞吐量、单路随机写平均时延等性…

算法训练营Day28

#Java #贪心 开源学习资料 Feeling and experiences&#xff1a; 这周来到了贪心算法&#xff0c;简要概述&#xff1a; 贪心算法是一种在每个步骤中都采取最优解&#xff08;即&#xff0c;在当前看来最好的解&#xff09;的算法设计策略。它通常用于求解优化问题。这种方…

动态静态网页

目录 动态静态网页设计中使用的核心技术&#xff1a; 动态静态网页本质区别&#xff1a; 动态静态网页设计中使用的核心技术&#xff1a; 在动态和静态网页设计中&#xff0c;有一些核心技术是常见的。下面是其中的一些&#xff1a; 动态网页设计中使用的核心技术&#xff1a…

Mysql的基本用法(上)非常详细、快速上手

上篇结束了java基础&#xff0c;本篇主要对Mysql中的一些常用的方法进行了总结&#xff0c;主要对查询方法进行了讲解&#xff0c;包括重要的多表查询用到的内连接和外连接等&#xff0c;以下代码可以直接复制到可视化软件中&#xff0c;方便阅读以及练习&#xff1b; SELECT *…

H5C3练习心得 2024.01.03(文字加载动画效果)--transition,动画渲染,遮罩层

&#xff08;一&#xff09;transition&#xff08;过渡效果&#xff09; 1.详解 通常将css的属性值更改后&#xff0c;浏览器会立即更新新的样式&#xff0c;例如在鼠标悬停在元素上时&#xff0c;通过 :hover 选择器定义的样式会立即应用在元素上。 在 CSS3 中加入了一项过…

VCG 指定Mesh面片颜色

文章目录 一、简介二、实现代码三、实现效果参考资料一、简介 由于VCG并没有提供可视化的模块,因此将指定Mesh面片的颜色就对我们后面测试结果很有用处了,VCG为我们提供了一个Mesh颜色属性,我们只需启用它即可进行面片的赋色操作。 二、实现代码 //VCG #include <vcg/co…