我是立体声重建的新手,经过大量的搜索,我需要一些帮助。
我正在尝试通过HeikoHirschmüller实现eSGM算法进行立体声重建。对于第一步(匹配成本计算),我使用Birchfield和Tomasi的Pixel Dissimilarity度量。
但是,我认为我没有得到正确的结果。在第一步中,我只是保存像素差异度,由其paper
的3.1.2节中的公式计算得出我运行我的代码,差异范围为16,并计算每个差异。这就是我得到的disparity = 1 这适用于disparity = 16
因此看起来两个图像都是叠加的,只是随着视差的增加而移位。
这是我的一个像素的代码:
/* Using the dissimilarity calculation from Depth Discontinuities by Pixel-to-Pixel Stereo
* published by Stan Birchfield and Carlo Tomasi (Proceedings of the 1998 IEEE International
* Conference on Computer Vision, Bombay, India).
*
* The dissimilarity between pixels xL and xR can be calculated with the following formula:
*
* d = min(d1(xL, xR, il, iR), d1(xR, xL, iR, iL))
*
* where, d1(xL, xR, il, iR) = max(0, iL - iRMax, iRMin - iL)
* and d1(xR, xL, iR, iL) = max(0, iR - iLMax, iLMin - iR)
* and iRMax = max(iRMinus, iRPlus, iR)
* and iRMin = min(iRMinus, iRPlus, iR)
* Similarly, d1(xR, xL, iR, iL) = max(0, iR - iLMax, iLMin - iR)
* and d1(xL, xR, iL, iR) = max(0, iL - iRMax, iRMin - iL)
* and iLMax = max(iLMinus, iLPlus, iL)
* and iLMin = min(iLMinus, iLPlus, iL)
* */
// Variables for the equation
uchar beforeRValue, rValue, afterRValue;
uchar beforeLValue, lValue, afterLValue;
uchar iRMinus, iRPlus, iRMax, iRMin;
uchar iLMinus, iLPlus, iLMax, iLMin;
int row, col, rCol, d;
for (row = 0; row < nRows; ++row)
for (col = 0; col < nCols; ++col)
for (d = 0; d < this->disparityRange; ++d)
{
// Calculating the equation
rCol = col - d;
if (rCol <= 0)
{
beforeRValue = this->rightImage.ptr<uchar>(row)[0];
rValue = this->rightImage.ptr<uchar>(row)[0];
}
else {
beforeRValue = this->rightImage.ptr<uchar>(row)[rCol - 1];
rValue = this->rightImage.ptr<uchar>(row)[rCol];
}
if (rCol == this->leftImage.cols)
afterRValue = this->rightImage.ptr<uchar>(row)[rCol];
else
afterRValue = this->rightImage.ptr<uchar>(row)[rCol + 1];
iRMinus = (rValue + beforeRValue) / 2;
iRPlus = (rValue + afterRValue) / 2;
iRMax = MAX(MAX(rValue, iRMinus), iRPlus);
iRMin = MIN(MIN(rValue, iRMinus), iRPlus);
beforeLValue = (col == 0 ? this->leftImage.ptr<uchar>(row)[col] : this->leftImage.ptr<uchar>(row)[col - 1]);
lValue = this->leftImage.ptr<uchar>(row)[col];
afterLValue = (col == this->leftImage.cols ? this->leftImage.ptr<uchar>(row)[col] : this->leftImage.ptr<uchar>(row)[col + 1]);
iLMinus = (lValue + beforeLValue) / 2;
iLPlus = (lValue + afterLValue) / 2;
iLMax = MAX(MAX(lValue, iLMinus), iLPlus);
iLMin = MIN(MIN(lValue, iLMinus), iLPlus);
costs[row][col][d] = MIN(MAX(MAX(0, lValue - iRMax), iRMin - lValue),
MAX(MAX(0, rValue - iLMax), iLMin - rValue));
}
如果有人能帮我理解我做错了什么,我真的很感激!
谢谢!
P.S。我起初试图获得工作代码,我现在不关心优化:)