【问题标题】:Depth Estimation from Disparity Map视差图的深度估计
【发布时间】:2022-11-21 15:39:44
【问题描述】:

我正在尝试从视差图中估计一个点的深度。 首先,我进行了立体校准并校正了图像,然后着手寻找视差图。我在 OpenCV 中使用了 StereoSGBM。由于视差是指立体对的左右图像中两个对应点之间的距离,因此:

x_right = x_left + 视差

从校准中我获得了外部和内部参数,然后计算了基线和焦距。 自z_cm = (baseline_cm * focal_pixels) / (disparity_pixels)

## Read image
img_left=cv.imread('images/testLeft/testL0.png')
img_right=cv.imread('images/testRight/testR0.png')
    
# Grayscale Images
frame_left = cv.cvtColor(img_left,cv.COLOR_BGR2GRAY)
frame_right = cv.cvtColor(img_right,cv.COLOR_BGR2GRAY)

# Undistort and rectify images
frame_left_rect = cv.remap(frame_left, stereoMapL_x, stereoMapL_y, cv.INTER_LANCZOS4, cv.BORDER_CONSTANT,0)
frame_right_rect = cv.remap(frame_right, stereoMapR_x, stereoMapR_y, cv.INTER_LANCZOS4, cv.BORDER_CONSTANT,0)
    
# Creating an object of StereoBM algorithm
Left_matcher = cv.StereoSGBM_create(
   minDisparity=-1, numDisparities=16*3,  
   blockSize=5,
   P1=8 * 2 * blockSize**2,
   P2=32 * 2 * blockSize**2,
   disp12MaxDiff=1,
   uniquenessRatio=10,
   speckleWindowSize=100,
   speckleRange=32,
   mode=cv.STEREO_SGBM_MODE_SGBM_3WAY

#===========================================================================
# Compute Disparity Map
#===========================================================================
disparity = Left_Matcher.compute(frame_left_rect, frame_right_rect)
# Convert to float32 and divide by 16 - read documentation for point cloud
disparity = np.float32(np.divide(disparity,16.0))

disp_test = cv.applyColorMap(np.uint8(disparity), cv.COLORMAP_PLASMA)
cv.imshow("Disparity Map",disp_test)  

#==========================================================================
# Depth Map
#==========================================================================
depth_map = np.ones(disparity.shape)
# Focal Length - Pixels | Baseline -cm | Depth_map - cm
depth_map = focal_length * Baseline /disparity

我的问题是深度不对。任何人都可以帮助如何使用视差图来深入了解。我可能会使用 reprojectImageTo3D,但我认为我的视差图中存在问题。

【问题讨论】:

    标签: python opencv depth disparity-mapping


    【解决方案1】:

    检查您的相机参数 fx、fy、Cx、Cy 是否符合图像的空间维度。

    【讨论】:

      猜你喜欢
      • 2013-10-13
      • 2020-01-26
      • 2014-02-21
      • 2013-11-26
      • 2014-11-29
      • 2020-03-12
      • 2020-06-15
      • 2014-05-10
      • 2018-10-22
      相关资源
      最近更新 更多