我在使用OpenCV计算深度图时遇到了问题。我知道两个立体图像之间的距离是通过以下公式计算的:
z = (baseline * focal) / (disparity * p)
,但我无法弄清楚如何使用深度图计算视差。我使用的代码如下,可以提供给我两张图像的视差图。import numpy as np
import cv2
# Load the left and right images in gray scale
imgLeft = cv2.imread('logga.png', 0)
imgRight = cv2.imread('logga1.png', 0)
# Initialize the stereo block matching object
stereo = cv2.StereoBM_create(numDisparities=16, blockSize=5)
# Compute the disparity image
disparity = stereo.compute(imgLeft, imgRight)
# Normalize the image for representation
min = disparity.min()
max = disparity.max()
disparity = np.uint8(6400 * (disparity - min) / (max - min))
# Display the result
cv2.imshow('disparittet', np.hstack((imgLeft, imgRight, disparity)))
cv2.waitKey(0)
cv2.destroyAllWindows()