I'm trying to port SGBM to the GPU using this library.

The results are very good but not as sharp as OpenCV's StereoBinarySGBM from the contrib repository (using CV_CS_CENSUS descriptor)

I've looked through the code and noticed that in the main function computeDisparityBinarySGBM in the part of computing the cost for each pixel, the cost is not simply popcount(left^right) (the result of the previous function hammingDistanceBlockMatching) but the cost contains a bit more elaborate formulas, depending on the pixel. For example,

if (y > 0)
{
const CostType* hsumSub = hsumBuf + ((std::max)(y - SH2 - 1, 0) % hsumBufNRows)*costBufSize;
const CostType* Cprev = !fullDP || y == 0 ? C : C - costBufSize;

for (x = D; x < width1*D; x += D)
{
const CostType* pixAdd = pixDiff + (std::min)(x + SW2*D, (width1 - 1)*D);
const CostType* pixSub = pixDiff + (std::max)(x - (SW2 + 1)*D, 0);

for (d = 0; d < D; d++)
{
C[x + d] = (CostType)(Cprev[x + d] + hv - hsumSub[x + d]);
}
}
}


(SIMD part omitted for brevity)

Where C[x + d] is the final cost which will be used in the dynamic programming part of the SGM algorithm.

I couldn't find any explanation to these addition and subtraction and was wondering if someone could provide an explanation or a reference for it

Thanks

edit retag close merge delete