Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
canny edge detection and gaussian blur
# Running first a gaussian blur (kernel size = 3)
# and then Canny edge detection (low/high = 1:2 or 1:3)
# is a handy way to get the boundaries
from matplotlib import image
from matplotlib import pyplot
import numpy
import cv2
view_from_windshield = image.imread('test.jpg')
working_copy = numpy.copy(view_from_windshield)
# first convert to grayscale
grayscale = cv2.cvtColor(working_copy, cv2.COLOR_RGB2GRAY)
#apply gaussian blur before canny edge detection
kernel_size=3
gaussian_blurred = cv2.GaussianBlur(grayscale,(kernel_size, kernel_size), 0)
# now apply canny edge detection threshold ratio 1:3
low_threshold = 60
high_threshold = 180
edges = cv2.Canny(gaussian_blurred, low_threshold, high_threshold)
#pyplot.imshow(grayscale, cmap='gray')
#pyplot.imshow(gaussian_blurred, cmap='gray')
pyplot.imshow(edges, cmap='Greys_r')
pyplot.show()
pyplot.imsave('edges.jpg', edges, cmap='Greys_r')
@anubhavsinha
Copy link
Author

anubhavsinha commented Aug 26, 2017

test

@anubhavsinha
Copy link
Author

anubhavsinha commented Aug 26, 2017

edges

@anubhavsinha
Copy link
Author

anubhavsinha commented Aug 26, 2017

After we have marked the boundaries in an image, we can identify various shapes. Hough Transform is one of such trick to identify the shapes, which we shall explore next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment