• 卷积的边缘像素填充


    #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; 
    }
  • 相关阅读:
    初谈面向对象
    java概述~至数组
    django一对多数据库模型
    Django url()函数详解
    python编码规范
    django的用户管理
    ubuntu下安装搜狗拼音
    乱七八糟的2013
    使用django进行微信公众平台开发
    我们要写的项目
  • 原文地址:https://www.cnblogs.com/xiaochi/p/12009404.html
Copyright © 2020-2023  润新知