You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
592 B

This file contains ambiguous Unicode characters!

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. 求xy方向的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