1高斯滤波 2.使用偏导数 3.求出梯度值
其中得出梯度是差异较大域的切线
port cv2 as cv
def edge_demo(image):
blurred = cv.GaussianBlur(image, (3, 3), 0)
gray = cv.cvtColor(blurred, cv.COLOR_BGR2GRAY)
xgrad = cv.Sobel(gray, cv.CV_16SC1, 1, 0)
ygrad = cv.Sobel(gray, cv.CV_16SC1, 0, 1)
edge_output = cv.Canny(xgrad,ygrad,50,150) ## 得出彩色边缘
cv.imshow("canny edge",edge_output)
dst = cv.bitwise_and(image, image, mask=edge_output) ##灰度值与sobel边缘与
cv.imshow("Color Edge", dst)
src = cv.imread("C:/Users/weiqiangwen/Desktop/sest/data/lena.jpg")
# cv.namedWindow("input contours",cv.WINDOW_AUTOSIZE)
cv.imshow("contours", src)
edge_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
print("--------- Python OpenCV Tutorial ---------")