This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import cv2
# Canny算子
def CannyFilter(img):
# 读取图像
src = img
########## Begin ##########
# 1. 高斯滤波
blur = cv2.GaussianBlur(src, (3, 3), 0)
# 2. 灰度转换
blur = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
# 3. 求x,y方向的Sobel算子
gradx = cv2.Sobel(blur, cv2.CV_16SC1, 1, 0)
grady = cv2.Sobel(blur, cv2.CV_16SC1, 0, 1)
# 4. 使用Canny函数处理图像,x,y分别是3求出来的梯度,低阈值50,高阈值150
edge_output = cv2.Canny(gradx, grady, 50, 150)
########## End ##########
return edge_output