【发布时间】: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