我们经常会有对图像边缘做扩展的需求.比如
opencv中使用copyMakeBorder()来完成这一功能
api

borderType分两种:
import sys
import cv2 as cv
def test():
    src = cv.imread("/home/sc/disk/keepgoing/opencv_test/lights.jpeg") 
    top = int(0.05 * src.shape[0])  # shape[0] = rows
    bottom = top
    left = int(0.04 * src.shape[1])  # shape[1] = cols
    right = left
    
    value = [0,0,0]
    borderType = cv.BORDER_CONSTANT
    dst1 = cv.copyMakeBorder(src, top, bottom, left, right, borderType, None, value)
    
    borderType = cv.BORDER_REPLICATE
    dst2 = cv.copyMakeBorder(src, top, bottom, left, right, borderType, None, value)
    
    cv.imshow("blackborder",dst1)
    cv.imshow("BORDER_REPLICATE",dst2)
    
    if 27 == cv.waitKey():
        cv.destroyAllWindows()
        
test()
效果如下:

原文:https://www.cnblogs.com/sdu20112013/p/11643420.html