opencvcopyMakeBorder拓展边界

    cv::Mat dst;
    cv::Mat src(4, 3, CV_8UC3,cv::Scalar(10,20,30));

    cv::copyMakeBorder(src, dst,2,2,1,1,cv::BORDER_REPLICATE);
    /*
    参数1:输入的数组
    参数2:输出的拓展边界后的数组
    参数3:在src上边界向上拓展的行数
    参数4:在src下边界向下拓展的行数
    参数5:在src的左边界向左拓展的列数
    参数6:在src的右边界向右拓展的列数
    参数7:borderType:边界拓展策略
        cv::BORDER_REPLICATE    复制法,也就是复制最边缘像素  aaaaaa | abcdefgh | hhhhhhh
        cv::BORDER_REFLECT :    对称法   fedcba | abcdefgh | hgfedcb
        cv::BORDER_REFLECT_101:对称法,也就是以最边缘像素为轴,gfedcb | abcdefgh | gfedcba
        cv::BORDER_CONSTANT:   常量法   iiiiii | abcdefgh | iiiiiii
        cv::BORDER_WRAP :              cdefgh | abcdefgh | abcdefg
*/


    std::cerr<<src<<std::endl;
    std::cerr<<dst<<std::endl;

    std::cerr<<src.rows<<std::endl;
    std::cerr<<src.cols<<std::endl;
    std::cerr<<dst.rows<<std::endl;
    std::cerr<<dst.cols<<std::endl;

cv::copyMakeBorder(src, padded, 0, m - src.rows, 0, n - src.cols, cv::BORDER_CONSTANT, cv::Scalar::all(0));

原文地址:https://www.cnblogs.com/liming19680104/p/15543164.html