import cv2 import numpy as np
img = cv2.imread('test.jpg')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_blur = cv2.GaussianBlur(img_gray, (3,3), 0)
sobelx = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=1, dy=0, ksize=5) sobely = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=0, dy=1, ksize=5) sobelxy = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=1, dy=1, ksize=5)
''' cv2.imshow('Sobel X', sobelx) cv2.waitKey(0) cv2.imshow('Sobel Y', sobely) cv2.waitKey(0) cv2.imshow('Sobel X Y using Sobel() function', sobelxy) cv2.waitKey(0) '''
edges = cv2.Canny(image=img_blur, threshold1=70, threshold2=70)
cv2.imshow('Canny Edge Detection', edges) cv2.waitKey(0) cv2.destroyAllWindows()
|