当前位置:网站首页>cv.copyMakeBorder(imwrite opencv)
cv.copyMakeBorder(imwrite opencv)
2022-07-29 22:49:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
文章目录
参考依据
OpenCV-Python官方教程:https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_core/py_basic_ops/py_basic_ops.html
设置边界框
如果你想给你的图片设置边界框,就像一个相框一样的东西,你就可以使用cv2.copyMakeBorder()
函数。但其在卷积操作、零填充等也得到了应用,并且可以用于一些数据增广操作。
参数
- src : 输入的图片
- top, bottom, left, right :相应方向上的边框宽度
- borderType:定义要添加边框的类型,它可以是以下的一种:
- cv2.BORDER_CONSTANT:添加的边界框像素值为常数(需要额外再给定一个参数)
- cv2.BORDER_REFLECT:添加的边框像素将是边界元素的镜面反射,类似于
gfedcb|abcdefgh|gfedcba
- cv2.BORDER_REFLECT_101 or cv2.BORDER_DEFAULT:和上面类似,但是有一些细微的不同,类似于
gfedcb|abcdefgh|gfedcba
- cv2.BORDER_REPLICATE:使用最边界的像素值代替,类似于
aaaaaa|abcdefgh|hhhhhhh
- cv2.BORDER_WRAP:不知道怎么解释,直接看吧,
cdefgh|abcdefgh|abcdefg
- value:如果borderType为
cv2.BORDER_CONSTANT
时需要填充的常数值。
实例
img = cv2.imread('testimg.png')
img = cv2.resize(img,(256,256))
cv2.imshow('origin',img),cv2.waitKey(0),cv2.destroyAllWindows()
replicate = cv2.copyMakeBorder(img,20,20,20,20,cv2.BORDER_REPLICATE)
cv2.imshow('replicate',replicate),cv2.waitKey(0),cv2.destroyAllWindows()
constant = cv2.copyMakeBorder(img,20,20,20,20,cv2.BORDER_CONSTANT,value=(255,255,255))
cv2.imshow('constant',constant),cv2.waitKey(0),cv2.destroyAllWindows()
reflect = cv2.copyMakeBorder(img,20,20,20,20,cv2.BORDER_REFLECT)
cv2.imshow('reflect',reflect),cv2.waitKey(0),cv2.destroyAllWindows()
reflect101 = cv2.copyMakeBorder(img,20,20,20,20,cv2.BORDER_REFLECT_101)
cv2.imshow('reflect101',reflect101),cv2.waitKey(0),cv2.destroyAllWindows()
wrap = cv2.copyMakeBorder(img,20,20,20,20,cv2.BORDER_WRAP)
cv2.imshow('wrap',wrap),cv2.waitKey(0),cv2.destroyAllWindows()
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129776.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢
随机推荐
专利说明书怎么写?
地狱挖掘者系列#1
The first round of the real offer harvester~ How does the big factory inspect the candidates?(with detailed answer)
撰写英文文献有哪些技巧?
MySQL数据库进阶篇
labview怎么做成应用程序(labview程序识别形状)
Codeforces Round #245 (Div. 1) A (dfs)
This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
canvas 中如何实现物体的点选(五)
八、HikariCP源码分析之ConcurrentBag一
通信岗秋招准备
BGP Federal Comprehensive Experiment
high-level-rest-client 判断索引是否存在
一、HikariCP源码分析之获取连接流程一
JZ23 链表中环的入口结点
cached_network_image 多个图片卡顿崩溃
网工知识角|轻松拿offer【网工面试题】三层交换机与路由器有什么区别?
CNCF Keith Chan:分布式云时代,云原生社区的发展与趋势
十一、HikariCP源码分析之HouseKeeper
NetWorker Knowledge Corner|Easy to get an offer [Networker Interview Questions] What is the difference between a Layer 3 switch and a router?