opencv 濾波器 邊緣檢測

#!  usr/bin/python
#   coding=utf-8

import numpy as np
import cv2
from scipy import ndimage

#   opencv 濾波器 

image = cv2.imread('test.jpg', 0)

# kernel_3x3 = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])

# kernel_5x5 = np.array([[-1, -1, -1, -1, -1],
#   [-1, 1, 2, 1, -1],
#   [-1, 2, 4, 2, -1],
#   [-1, 1, 2, 1, -1],
#   [-1, -1, -1, -1, -1]])

# k3 = ndimage.convolve(image, kernel_3x3)
# k5 = ndimage.convolve(image, kernel_5x5)

# sigma = 0
# blurred = cv2.GaussianBlur(image, (11, 11), sigma)

# cv2.imshow('3*3', k3)
# cv2.imshow('5*5', k5)
# cv2.imshow('blurred', blurred)


lap = cv2.Laplacian(image, cv2.CV_8U)

sobel_x = cv2.Sobel(image, cv2.CV_16S, 1, 0)
sobel_y = cv2.Sobel(image, cv2.CV_16S, 0, 1)
abs_x = cv2.convertScaleAbs(sobel_x)
abs_y = cv2.convertScaleAbs(sobel_y)
sobel = cv2.addWeighted(abs_x, 0.5, abs_y, 0.5, 0)

canny = cv2.Canny(image, 10, 150)

cv2.imshow('lap', lap)

# cv2.imshow('sobel_x', sobel_x)
# cv2.imshow('sobel_y', sobel_y)
cv2.imshow('sobel', sobel)

cv2.imshow('canny', canny)

cv2.waitKey()
cv2.destroyAllWindow()
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容