zoukankan      html  css  js  c++  java
  • 图像的padding操作

    为了完成卷积后图像大小不变,原始图像需要进行边界填充

    copyMakeBorder(src,dst,top,bottom,left,right,bordertype,value);

    bordertype:

    BORDER_DEFAULT  填充黑色

    BORDER_CONSTANT  用指定像素填充边界

    BORDER_REPLICATE  用一只边缘像素填充边缘像素

    BORDER_WARP  用另一边像素来补偿填充

    #include"pch.h"
    #include<iostream>
    #include<opencv2/opencv.hpp>
    
    using namespace std;
    using namespace cv;
    
    int main(int argc, char**argv)
    {
        Mat src, dst;
        src = imread("b.jpg");
        if (src.empty())
        {
            cout << "Load img failed" << endl;
            return -1;
        }
        imshow("input img", src);
    
        int top = (int)(src.rows*0.05);
        int bottom = (int)(src.rows*0.05);
        int left = (int)(src.cols*0.05);
        int right = (int)(src.cols*0.05);
    
        RNG rng(12345);
        int borderType = BORDER_DEFAULT;
        int c = 0;
    
        while (true)
        {
            c = waitKey(500);
            if ((char)c == 27)//esc
            {
                break;
            }
            if ((char)c == 'r')
            {
                borderType = BORDER_REPLICATE;
            }
            else if ((char)c == 'w')
            {
                borderType = BORDER_WRAP;
            }
            else if ((char)c == 'c')
            {
                borderType = BORDER_CONSTANT;
            }
            else
            {
                borderType = BORDER_DEFAULT;
            }
            Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
            copyMakeBorder(src, dst, top, bottom, left, right, borderType, color);
            imshow("output", dst);
        }
        waitKey(0);
        return 0;
    }
  • 相关阅读:
    C++STL——vector
    大数常用计算模板及例题
    在线算法&离线算法
    线段树——hdu1166敌兵布阵
    C++STL——堆栈
    C++STL——优先队列
    C++STL——队列
    图的建立——图的两种存储结构
    Manacher算法——最长回文子串
    HttpClient的几个实现类
  • 原文地址:https://www.cnblogs.com/wangtianning1223/p/12082876.html
Copyright © 2011-2022 走看看