【问题标题】:Constructing right-view image from left-view image and disparity map从左视图图像和视差图构造右视图图像
【发布时间】:2019-06-21 20:02:30
【问题描述】:

我正在尝试从左视图图像及其视差图构建右视图图像。我使用middleburry dataset 2003 (http://vision.middlebury.edu/stereo/data/scenes2003/) 和全尺寸图像,这意味着视差图中每个像素的值v对应于左视图图像上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);
            }
        }
    }
}

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

左视图:

真实视差图:

我得到了什么:

提前感谢您的帮助。

【问题讨论】:

    标签: image opencv image-processing stereo-3d disparity-mapping


    【解决方案1】:

    好的,我想通了。我正在使用 imread 加载视差图像,但没有指定它是灰度图像(使用 IMREAD_GRAYSCALE)。因此,openCV 将其加载为 RGB 图像,当我使用 at() 访问视差像素时,我将 uchar 指定为所需类型。所以我猜有一种从 Vec3b 到 uchar 的转换会给出错误的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2012-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多