目录
- 原理
- Sobel检测算子
-
- Laplacian算子
- Canny边缘检测
-
原理
Sobel检测算子
方法
应用
sobel_x_or_y=cv.Sobel(src,ddepth,dx,dy,dst,ksize,scale,delta,borderType)
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
img=cv.imread('./汪学长的随堂资料/4/图像操作/cat.jpg',0)
x=cv.Sobel(img,cv.CV_16S,1,0)
y=cv.Sobel(img,cv.CV_16S,0,1)
absx=cv.convertScaleAbs(x)
absy=cv.convertScaleAbs(y)
res=cv.addWeighted(absx,0.5,absy,0.5,0)
plt.imshow(res,cmap='gray')
x=cv.Sobel(img,cv.CV_16S,1,0,ksize=-1)
y=cv.Sobel(img,cv.CV_16S,0,1,ksize=-1)
absx=cv.convertScaleAbs(x)
absy=cv.convertScaleAbs(y)
res=cv.addWeighted(absx,0.5,absy,0.5,0)
plt.imshow(res,cmap='gray')
Laplacian算子
laplacian=cv.Laplacian(src,ddepth[,dst[,ksize[,scale[,delta[,borderType]]]]])
res=cv.Laplacian(img,cv.CV_16S)
res=cv.convertScaleAbs(res)
plt.imshow(res,cmap='gray')
Canny边缘检测
原理
canny=cv.Canny(img,threshold1,threshold2)
res=cv.Canny(img,0,100)
plt.imshow(res,cmap='gray')