openCV:边界处理

#include <iostream>  
#include<opencv2/opencv.hpp>
#include "math.h"  

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
	Mat src,dst;//初始化一个操作对象
	src = imread("C:/Users/JAY/Desktop/Others/tang.jpg");
	if (!src.data)//判断图片是否加载进来
	{
		cout << "不能加载图片" << endl;
		return -1;
	}
	namedWindow("加载的图片", WINDOW_AUTOSIZE);
	imshow("加载的图片", src);//""内命名一致,才能显示在一个窗口

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

	int c = 0;
	while (true)
	{
		c = waitKey(500);
		if ((char)c==27)
		{
			break;
		}
		if ((char)c=='r')//键盘输入对应键,显示不同效果
		{
			borderType = BORDER_REPLICATE;//插值计算
		}
		else if ((char)c == 'v')
		{
			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, botton, left, right, borderType);
		imshow("重绘边缘图案", dst);
	}


	waitKey(0);
	return 0;
}

结果

 默认BORDER_DEFAULT

 BORDER_REPLICATE

 BORDER_WRAP

 BORDER_CONSTANT

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值