[英]How to acquire depth map from stereo - KITTI dataset
After trying example stated in opencv documentation .在尝试了 opencv 文档中所述的示例之后。
When I tried the same code on KITTI image pair I get this:当我在KITTI图像对上尝试相同的代码时,我得到了这个:
The code I am using right now looks like this, changing the parameters in StereoBM_create did not help much:我现在使用的代码如下所示,更改 StereoBM_create 中的参数并没有太大帮助:
import numpy as np
import cv2
from matplotlib import pyplot as plt
imgL = cv2.imread('000002_left.png',0)
imgR = cv2.imread('000002_right.png',0)
stereo = cv2.StereoBM_create(numDisparities=16, blockSize=15)
#stereo = cv2.StereoBM_create(numDisparities=64, blockSize=17)
disparity = stereo.compute(imgL,imgR)
cv2.imwrite('depth_map.png', disparity)
disp_v2 = cv2.imread('depth_map.png')
disp_v2 = cv2.applyColorMap(disp_v2, cv2.COLORMAP_JET)
plt.imshow(disp_v2)
cv2.imwrite('depth_map_coloured.png', disp_v2)
plt.show()
Question is: How can I make the depth map better?问题是:我怎样才能使深度图更好?
In my experience, StereoBM (OpenCV) doesn't work with KITTI images.根据我的经验,StereoBM (OpenCV) 不适用于 KITTI 图像。 Maybe because KITTI images are much more complex.
也许是因为 KITTI 图像要复杂得多。
But I achieved to get good results using this:但是我使用这个取得了很好的结果:
https://github.com/ialhashim/DenseDepth https://github.com/ialhashim/DenseDepth
You should adjust the parameters of the stereo matcher in opencv.您应该在 opencv 中调整立体匹配器的参数。
This is a function inside a class I created.这是我创建的类中的一个函数。 It can be seen that I adjust some parameters such as a number of disparities, min disparity etc.:
可以看出,我调整了一些参数,例如视差数、最小视差等:
def get_stereo_map(self, image_idx):
left_RGB = self.get_left_RGB(image_idx) # left RGB image
right_RGB = self.get_right_RGB(image_idx) # right RGB image
# compute depth map from stereo
stereo = cv2.StereoBM_create()
stereo.setMinDisparity(0)
num_disparities = 16*5
stereo.setNumDisparities(num_disparities)
stereo.setBlockSize(15)
stereo.setSpeckleRange(16)
# stereo.setSpeckleWindowSize(45)
stereo_depth_map = stereo.compute(
cv2.cvtColor(np.array(left_RGB), cv2.COLOR_RGB2GRAY),
cv2.cvtColor(np.array(right_RGB), cv2.COLOR_RGB2GRAY))
# by equation + divide by 16 to get true disperities
stereo_depth_map = (self.storage.focal_pix_RGB * self.storage.baseline_m_RGB) \
/ (stereo_depth_map/16)
stereo_depth_map = DataParser.crop_redundant(stereo_depth_map)
return stereo_depth_map
For full code refer to my repo: https://github.com/janezlapajne/kitty-stereo-dataset-parser Ground truth from lidar and stereo distance map are also included.有关完整代码,请参阅我的 repo: https : //github.com/janezlapajne/kitty-stereo-dataset-parser还包括来自激光雷达和立体距离图的地面实况。 Hope it helps anyone.
希望它可以帮助任何人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.