1. 程式人生 > >python-opencv(8):影象的腐蝕與膨脹

python-opencv(8):影象的腐蝕與膨脹

語法:

dst=cv2.erode(src,kernel,iterations) 
dst=cv2.dilate(src,kernel,iterations)

kernel:卷積核     kernel=np.ones((5,5),np.uint8)

程式示例:

import cv2
import numpy as np
img=cv2.imread("2.png",cv2.IMREAD_UNCHANGED)
k=np.ones((5,5),np.uint8)
result1=cv2.erode(img,k,5)
result2=cv2.dilate(img,k,5)
cv2.imshow("original",img)
cv2.imshow("result1",result1)
cv2.imshow("result2",result2)
cv2.waitKey()
cv2.destroyAllWindows()

結果: