【学习体会】OpenCV的cv::remap使用

 

 

#include 
#include 

int main()
{
    cv::Mat img, output; // img 输入图像 ; src 最终输出的图像
    cv::Mat map_x, map_y,map_xy;
    img = cv::imread("../fg2.bmp");
    cv::imshow("INPUT_TITLE", img);

    //建立映射表
    // map_x.create(img.size(), CV_32FC1);
    // map_y.create(img.size(), CV_32FC1);
    map_xy.create(img.size(),CV_32FC2);

    float alpha =0.7;
    for (int row = 0; row < img.rows; row++)
    {
        for (int col = 0; col < img.cols; col++)
        {
            if (col > (img.cols * ((1-alpha)/2)) && col < (img.cols * ((1+alpha)/2)) && row > (img.rows * ((1-alpha)/2)) && row < (img.rows * ((1+alpha)/2)))
            {

                // map_x.at(row, col) =(1/alpha) * (col - (img.cols * ((1-alpha)/2)));
                // map_y.at(row, col) =(1/alpha) * (row - img.rows * ((1-alpha)/2) - ((1-alpha)/2));
                map_xy.at(row, col)[0] =(1/alpha) * (col - (img.cols * ((1-alpha)/2)));
                map_xy.at(row, col)[1] =(1/alpha) * (row - img.rows * ((1-alpha)/2) - ((1-alpha)/2));

            }
            else
            {
                // map_x.at(row, col) = 0;
                // map_y.at(row, col) = 0;
                map_xy.at(row, col)[0] = 0;
                map_xy.at(row, col)[1] = 0;
            }
        }
    }

    cv::remap(img, output, map_xy, cv::Mat(), cv::INTER_NEAREST, cv::BORDER_CONSTANT, cv::Scalar(0, 0, 255));
    //cv::remap(img, output, map_x, map_y, cv::INTER_NEAREST, cv::BORDER_CONSTANT, cv::Scalar(0, 0, 255));
    imshow("OUTPUT_TITLE", output);
    cv::waitKey(0);

    return 0;
}

你可能感兴趣的:(学习体会,计算机视觉,opencv,图像处理)