繁体   English   中英

从左视图图像和视差图构造右视图图像

[英]Constructing right-view image from left-view image and disparity map

我正在尝试从左视图图像及其视差图构造右视图图像。 我将Middleburry数据集2003( http://vision.middlebury.edu/stereo/data/scenes2003/ )与完整尺寸的图像一起使用,这意味着视差图中每个像素的值v对应于上左视图图像。

我的算法很简单。 对于左视图图像中坐标(x,y)的每个像素,我将此像素复制到右视图图像上但在坐标(x-d,y)处,其中d是坐标处视差图的值(x,y)。 如果视差值为0,我什么都不做。 我使用openCV来处理图像。

这是我的代码:

void computeCorrespondingImage(const cv::Mat &img, const cv::Mat &disparity, cv::Mat &dest,
                           const bool leftInput, const int disparityScale)
{
    const int shiftDirection = leftInput ? -1 : 1;
    dest.create(img.rows, img.cols, img.type());

    for (int i(0) ; i < img.rows ; ++i) {
        for (int j(0) ; j < img.cols  ; ++j) {
            const uchar d(disparity.at<const uchar>(i, j));
            const int computedColumn(j + shiftDirection * (d / disparityScale));

            // No need to consider pixels who would be outside of the image's bounds
            if (d > 0 && computedColumn >= 0 && computedColumn < img.cols) {
                dest.at<cv::Vec3b>(i, computedColumn) = img.at<const cv::Vec3b>(i, j);
            }
        }
    }
}

由于视差图是真实的视差图,因此我希望获得的图像与数据集中提供的右视图图像非常相似,但有一些黑色区域(视差未知)。 但是,由于某些原因,就像计算出的右视图图像在中心被分割一样,使得该图像不可用。

左视图图片:

在此处输入图片说明

真实差距图:

在此处输入图片说明

我得到的是:

在此处输入图片说明

预先感谢您的帮助。

好的,我知道了。 我在加载视差图像时未指定其为灰度图像(使用IMREAD_GRAYSCALE)。 因此,openCV将其作为RGB图像加载,当我使用at()访问视差像素时,我将uchar指定为所需类型。 所以我猜想是从Vec3b到uchar的某种转换提供了错误的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM