大家好,又见面了,我是你们的朋友全栈君。
OpenCV-Python官方教程:https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_core/py_basic_ops/py_basic_ops.html
如果你想给你的图片设置边界框,就像一个相框一样的东西,你就可以使用cv2.copyMakeBorder()
函数。但其在卷积操作、零填充等也得到了应用,并且可以用于一些数据增广操作。
gfedcb|abcdefgh|gfedcba
gfedcb|abcdefgh|gfedcba
aaaaaa|abcdefgh|hhhhhhh
cdefgh|abcdefgh|abcdefg
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