Opencv图像深度估计

参考链接: https://learnopencv.com/introduction-to-epipolar-geometry-and-stereo-vision/
数据集: https://vision.middlebury.edu/stereo/data/scenes2014/
测试图片1(请从源数据集下载,展示的图片为截图):
Opencv图像深度估计_第1张图片
测试图片2(请从源数据集下载,展示的图片为截图):
Opencv图像深度估计_第2张图片

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

@author: Wenqing Zhou ([email protected])
@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)

你可能感兴趣的:(深度学习,图像,立体成像,opencv,双目成像)