-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanny_edge.py
35 lines (26 loc) · 1.12 KB
/
canny_edge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cv2
# Read the original image
img = cv2.imread(r'D:\computer_vision\data\nemo.jpg',0)
# Blur the image for better edge detection
img_blur = cv2.GaussianBlur(img,(3,3),0)
# Canny Edge Detection
edges = cv2.Canny(image=img_blur, threshold1=100, threshold2=200)
# Display Canny Edge Detection Image
cv2.imshow('Canny Edge Detection', edges)
cv2.waitKey(0)
# Sobel Edge Detection
# Read the original image
img1 = cv2.imread(r'D:\computer_vision\data\tiger.jpg',0)
# Blur the image for better edge detection
img_blur = cv2.GaussianBlur(img1,(3,3),0)
sobelx = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=1, dy=0, ksize=5) # Sobel Edge Detection on the X axis
sobely = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=0, dy=1, ksize=5) # Sobel Edge Detection on the Y axis
sobelxy = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=1, dy=1, ksize=5) # Combined X and Y Sobel Edge Detection
# Display Sobel Edge Detection Images
cv2.imshow('Sobel X', sobelx)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imshow('Sobel Y', sobely)
cv2.waitKey(0)
cv2.imshow('Sobel X Y using Sobel() function', sobelxy)
cv2.waitKey(0)