#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace cv;
using namespace std;

Mat src, dst,dst2,gray_src;
char* INPUT_WIN = "input image";
char* OUTPUT_WIN = "binary image";
int threshold_value = 127;
int threshold_max = 255;
int type_value = 2;
int type_max = 4;


int main()
{

    src = imread(".//pic//kate.png");

    namedWindow(INPUT_WIN, CV_WINDOW_AUTOSIZE);
    namedWindow(OUTPUT_WIN, CV_WINDOW_AUTOSIZE);
    imshow(INPUT_WIN, src);


    int top = (int)(0.05 * src.rows);
    int bottom = (int)(0.05 * src.rows);
    int left = (int)(0.05 * src.cols);
    int right = (int)(0.05 * src.cols);
    RNG rng(12345);

    //卷积边缘
    //openCV默认的处理方法是:BORDER_DEFAULT   边缘同值向外填充(BORDER_REPLICATE)
    //此外还有:
    //BORDER_CONSTANT 填充边缘用指定像素值
    //BORDER_REPLICATE 填充边缘像素用已知的边缘像素值
    //BORDER_WRAP 用另外一边的像素来补偿填充

    int borderType = BORDER_DEFAULT; 

    int c = 0;

    while (1)
    {
        c = waitKey(500);
        if ((char)c == 27)
        {
            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_REPLICATE;
        }
        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_WIN, dst);
    }


    waitKey(0);
    return 0; 
}