Opencv图像深度估计

参考链接: https://learnopencv.com/introduction-to-epipolar-geometry-and-stereo-vision/
数据集: https://vision.middlebury.edu/stereo/data/scenes2014/
测试图片1(请从源数据集下载,展示的图片为截图):
在这里插入图片描述
测试图片2(请从源数据集下载,展示的图片为截图):
在这里插入图片描述

# -*- coding: utf-8 -*-
"""
Created on Wed Aug 11 11:47:26 2021

@author: Wenqing Zhou (zhou.wenqing@qq.com)
@github: https://github.com/ouening
"""
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Reading the left and right images.

imgL = cv2.imread(r"E:\Downloads\Adirondack-perfect\im0.png",0)
imgR = cv2.imread(r"E:\Downloads\Adirondack-perfect\im1.png",0)

# Setting parameters for StereoSGBM algorithm
minDisparity = 0;
numDisparities = 64;
blockSize = 8;
disp12MaxDiff = 1;
uniquenessRatio = 10;
speckleWindowSize = 10;
speckleRange = 8;

# Creating an object of StereoSGBM algorithm
stereo = cv2.StereoSGBM_create(minDisparity = minDisparity,
        numDisparities = numDisparities,
        blockSize = blockSize,
        disp12MaxDiff = disp12MaxDiff,
        uniquenessRatio = uniquenessRatio,
        speckleWindowSize = speckleWindowSize,
        speckleRange = speckleRange
    )

# Calculating disparith using the StereoSGBM algorithm
disp = stereo.compute(imgL, imgR).astype(np.float32)
disp = cv2.normalize(disp,0,255,cv2.NORM_MINMAX)

heatmap = np.uint8(255*disp)
heatmap = cv2.applyColorMap(heatmap,cv2.COLORMAP_JET)#颜色变换
plt.imshow(heatmap[:,:,::-1])
plt.show()

# Displaying the disparity map
# cv2.namedWindow("disparity", cv2.WINDOW_NORMAL)
# cv2.imshow("disparity",disp)
# cv2.waitKey(0)

在这里插入图片描述

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值