我的OpenCV学习笔记(五):给图像加上边框

这篇博客介绍了如何利用OpenCV的copyMakeBorder函数为图像添加边框,内容包括函数的使用方法和示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这段程序来自OpenCV教程,使用copyMakeBorder函数来给图像加上边框:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;




int main()
{
	Mat image,result;
	//获得边界的类型
	int borderType = BORDER_REPLICATE;
	//输入字符
	int c;

	image = imread("D:/picture/img.tif");
	if(!image.data)
	{
		printf("fail to load image\n");
		return -1;
	}
	//使用说明
	cout<<"使用说明:"<<endl;
	cout<<"按键c设置边界为随机的颜色"<<endl;
	cout<<"按键r设置边界为原图的颜色"<<endl;
	cout<<"按键按键ESC退出程序"<<endl;

	//颜色随机值
	Scalar value;
	//随机数种子
	RNG rng(12345);
	//初始化参数:边框的粗细
	int top = (int) (0.05*image.rows);
	int bottom = (int) (0.05*image.rows);
	int left = (int) (0.05*image.cols);
	int right = (int) (0.05*image.cols);

	result = image;
	//imshow("显示结果",result);
	
	while(true)
	{
		c = waitKey(500);
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值