SGBM pixAdd pixSub

asked 2019-01-06 03:38:15 -0500

La bla bla gravatar image

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++)
            int hv = hsumAdd[x + d] = (CostType)(hsumAdd[x - D + d] + pixAdd[d] - pixSub[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


edit retag flag offensive close merge delete



Maybe you can try to ask the author of the code. Corresponding pull requests are:

The work was done for the GSoC 2015. You can also ask for a reference in the literature.

Eduardo gravatar imageEduardo ( 2019-01-06 08:27:48 -0500 )edit