Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

OpenCV - finding edges using Canny

import cv2 as cv
import sys

if len(sys.argv) != 2:
    exit(f"Usage: {sys.argv[0]} FILENAME")

filename = sys.argv[1]

original = cv.imread(filename)
cv.imshow('Origianl', original)

edges = cv.Canny(original, =125, 175) # providing two thresholds
cv.imshow('Edges', edges)
cv.waitKey(0)
  • If we first blur the image and then run Canny on the blurred image, we get a lot less edges.

Dilate an image using structuring elements