OpenCV中的laplacian運算元邊緣檢測
阿新 • • 發佈:2021-02-16
OpenCV中的laplacian運算元邊緣檢測
程式碼實現:
#二、Laplacian運算元
#1.自帶laplacian的api
cv2.imshow('img',img)
laplacian = cv2.Laplacian(img,cv2.CV_32F,ksize=3) #ksize預設為1
laplacian = cv2.convertScaleAbs(laplacian)
cv2.imshow('laplacian1',laplacian)
cv2.waitKey()
#2.自定義拉普拉斯卷積核
kernel = np. array([[1,1,1],[1,-8,1],[1,1,1]]) #八領域卷積核
dst = cv2.filter2D(img,cv2.CV_32F,kernel=kernel)
laplacian = cv2.convertScaleAbs(dst)
cv2.imshow('laplacian2',laplacian)
cv2.waitKey()
執行結果: