cv2.copyMakeBorder()

参考cv2.copyMakeBorder - 云+社区 - 腾讯云

OpenCV-Python是旨在解决计算机视觉问题的Python绑定库。cv2.copyMakeBorder()方法用于在像相框一样的图像周围创建边框。

用法: cv2.copyMakeBorder(src, top, bottom, left, right, borderType, value)

参数:
src:它是源图像。
top:它是顶部方向上的像素数的边框宽度。
bottom:它是底部方向上的像素数的边框宽度。
left:它是左侧像素的边界宽度。
right:它是沿正确方向的像素数的边框宽度。
borderType:它描述了要添加哪种边框。它由cv2.BORDER_CONSTANT,cv2.BORDER_REFLECT等标志定义
value:这是一个可选参数,如果border type为,则描述边框的颜色cv2.BORDER_CONSTANT

返回值:它返回一个图像。

borderType标志如下所述:

cv2.BORDER_CONSTANT: It adds a constant colored border. The value should be given as next argument.
cv2.BORDER_REFLECT: The border will be mirror reflection of the border elements. Suppose, if image contains letters “abcdefg” then output will be “gfedcba|abcdefg|gfedcba“.
cv2.BORDER_REFLECT_101 or cv2.BORDER_DEFAULT: It does the same works as cv2.BORDER_REFLECT but with slight change. Suppose, if image contains letters “abcdefgh” then output will be “gfedcb|abcdefgh|gfedcba“.
cv2.BORDER_REPLICATE: It replicates the last element. Suppose, if image contains letters “abcdefgh” then output will be “aaaaa|abcdefgh|hhhhh“.

用于以下所有示例的图像:

示例1:

# Python program to explain cv2.copyMakeBorder() method  
   
# importing cv2  
import cv2  
   
# path  
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
   
# Reading an image in default mode 
image = cv2.imread(path) 
   
# Window name in which image is displayed 
window_name = 'Image'
  
# Using cv2.copyMakeBorder() method 
image = cv2.copyMakeBorder(image, 10, 10, 10, 10, cv2.BORDER_CONSTANT) 
  
# Displaying the image  
cv2.imshow(window_name, image)

输出:

示例2:

# Python program to explain cv2.copyMakeBorder() method  
   
# importing cv2  
import cv2  
   
# path  
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
   
# Reading an image in default mode 
image = cv2.imread(path) 
   
# Window name in which image is displayed 
window_name = 'Image'
  
# Using cv2.copyMakeBorder() method 
image = cv2.copyMakeBorder(image, 100, 100, 50, 50, cv2.BORDER_REFLECT) 
  
# Displaying the image  
cv2.imshow(window_name, image)

输出:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wanderer001

ROIAlign原理

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值