Skip to content

Instantly share code, notes, and snippets.

@anubhavsinha
Created August 26, 2017 21:43
Show Gist options
  • Save anubhavsinha/9beb379904e92d8644a0f5eb33c9e11e to your computer and use it in GitHub Desktop.
Save anubhavsinha/9beb379904e92d8644a0f5eb33c9e11e to your computer and use it in GitHub Desktop.
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

edges

@anubhavsinha
Copy link
Author

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