Python/OpenCV:从立体图像计算深度图 [英] Python/OpenCV: Computing a depth map from stereo images

查看:138
本文介绍了Python/OpenCV:从立体图像计算深度图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个立体图像,我想用它们来计算深度图.虽然不幸的是我不知道 C/C++,但我知道 python——所以当我发现
(来源:opencv.org)

调整参数并不能改善问题.我能找到的所有文档都是针对 openCV 代码的原始 C 版本,而不是 python-library-equivalent.不幸的是,我无法使用它来改善情况.

任何帮助将不胜感激!

解决方案

您的图像处理方式不对.

看图片,灯后面的锡罐可以让你计算出两张图片的相机位置,

只需更改此:

# vimgR = cv2.imread('Yeuna9x.png',0)imgL = cv2.imread('SuXT483.png',0)#^

如果您查看教程中的图像,他们说是 left 框架,它与您的 right 框架相同.

这是我更改后的结果.

I have two stereo images that I'd like to use to compute a depth map. While I unfortunately do not know C/C++, I do know python-- so when I found this tutorial, I was optimistic.

Unfortunately, the tutorial appears to be somewhat out of date. It not only needs to be tweaked to run at all (renaming 'createStereoBM' to 'StereoBM') but when it does run, it doesn't give a good result, even on the example stereo-images that were used in the tutorial itself.

Here's an example:

import numpy as np
import cv2
from matplotlib import pyplot as plt

imgL = cv2.imread('Yeuna9x.png',0)
imgR = cv2.imread('SuXT483.png',0)

stereo = cv2.StereoBM(1, 16, 15)
disparity = stereo.compute(imgL, imgR)

plt.imshow(disparity,'gray')
plt.show()

The result:

This looks very different from what the author of the tutorial achieves:


(source: opencv.org)

Tweaking the parameters does not improve matters. All documentation I've been able to find is for the original C-version of openCV code, not the python-library-equivalent. I unfortunately haven't been able to use this to improve things.

Any help would be appreciated!

解决方案

You have the images the wrong way around.

Look at the images, the tin behind the lamp lets you work out the camera locations of the two images,

Just change this:

#  v
imgR = cv2.imread('Yeuna9x.png',0)
imgL = cv2.imread('SuXT483.png',0)
#  ^

If you look at the image in the tutorial which they say is the left frame, it the same as your right one.

Here's my result after the change.

这篇关于Python/OpenCV:从立体图像计算深度图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆