Error: The document of the warpAffine is not in accordance with the source code

asked 2018-07-07 01:06:51 -0600

Yantao Xie gravatar image

The warpAffine's document says about the parameter flags:

flags: combination of interpolation methods (see InterpolationFlags) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation ( dst→src ).

which means the M will be inverted when WARP_INVERSE_MAP is set. But in the source code of the warpAffine

if( !(flags & WARP_INVERSE_MAP) )
{
    double D = M[0]*M[4] - M[1]*M[3];
    D = D != 0 ? 1./D : 0;
    double A11 = M[4]*D, A22=M[0]*D;
    M[0] = A11; M[1] *= -D;
    M[3] *= -D; M[4] = A22;
    double b1 = -M[0]*M[2] - M[1]*M[5];
    double b2 = -M[3]*M[2] - M[4]*M[5];
    M[2] = b1; M[5] = b2;
}

it says the M will be inverted default, i.e., when the WARP_INVERSE_MAP is NOT set.

Do I make a mistake or the document is not in accordance with the source?

edit retag flag offensive close merge delete

Comments

1

it's admittedly confusing (why is it that backwards), but imho, the code does exactly, what the docs specify.

Otherwise (if the flag is NOT set), the transformation is first inverted with invertAffineTransform and then put in the formula above instead of M.

berak gravatar imageberak ( 2018-07-07 04:07:48 -0600 )edit