Created
May 24, 2019 23:48
-
-
Save pknowledge/05d68179cdb364e4fa4db608517f8d17 to your computer and use it in GitHub Desktop.
Canny Edge Detection in OpenCV Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| img = cv2.imread("lena.jpg") | |
| img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
| canny = cv2.Canny(img, 100, 200) | |
| titles = ['image', 'canny'] | |
| images = [img, canny] | |
| for i in range(2): | |
| plt.subplot(1, 2, i+1), plt.imshow(images[i], 'gray') | |
| plt.title(titles[i]) | |
| plt.xticks([]),plt.yticks([]) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| img = cv2.imread("messi5.jpg", cv2.IMREAD_GRAYSCALE) | |
| lap = cv2.Laplacian(img, cv2.CV_64F, ksize=3) | |
| lap = np.uint8(np.absolute(lap)) | |
| sobelX = cv2.Sobel(img, cv2.CV_64F, 1, 0) | |
| sobelY = cv2.Sobel(img, cv2.CV_64F, 0, 1) | |
| edges = cv2.Canny(img,100,200) | |
| sobelX = np.uint8(np.absolute(sobelX)) | |
| sobelY = np.uint8(np.absolute(sobelY)) | |
| sobelCombined = cv2.bitwise_or(sobelX, sobelY) | |
| titles = ['image', 'Laplacian', 'sobelX', 'sobelY', 'sobelCombined', 'Canny'] | |
| images = [img, lap, sobelX, sobelY, sobelCombined, edges] | |
| for i in range(6): | |
| plt.subplot(2, 3, i+1), plt.imshow(images[i], 'gray') | |
| plt.title(titles[i]) | |
| plt.xticks([]),plt.yticks([]) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks