Ask Your Question

Revision history [back]

What does the MapAffine::inverseMap() function do?

What does the following function Inversewarp do? I expected it to use the "this" affine mapping and warp the image, but everytime I run I get the exact same warp - doesnt matter what my mapping is - the code seems to suggest a constant map. I am new to opencv, so I could be missing something basic. What am I missing?

It is from opencv/source/opencv_contrib/modules/reg/src/mapaffine.cpp

    void MapAffine::inverseWarp(const Mat& img1, Mat& img2) const
{
    // Rows and columns in destination
    Mat dest_r, dest_c;
    dest_r.create(img1.size(), CV_32FC1);
    dest_c.create(img1.size(), CV_32FC1);
    for(int r_i = 0; r_i < img1.rows; ++r_i)
    {
        for(int c_i = 0; c_i < img1.cols; ++c_i)
        {
            dest_c.at<float>(r_i, c_i) = float(c_i*linTr_(0, 0) + r_i*linTr_(0, 1) + shift_(0));
            dest_r.at<float>(r_i, c_i) = float(c_i*linTr_(1, 0) + r_i*linTr_(1, 1) + shift_(1));
        }
    }

    //remap(img1, img2, dest_c, dest_r, INTER_CUBIC, BORDER_REPLICATE);
    // Parts that cannot be interpolated will be as in img1 (BORDER_TRANSPARENT means that
    // remap will not touch them).
    img1.copyTo(img2);
    remap(img1, img2, dest_c, dest_r, INTER_CUBIC, BORDER_TRANSPARENT);
}