Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

You're reading from  Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

Product type Book
Published in Feb 2020
Publisher Packt
ISBN-13 9781789531619
Pages 372 pages
Edition 3rd Edition
Languages
Authors (2):
Joseph Howse Joseph Howse
Profile icon Joseph Howse
Joe Minichino Joe Minichino
Profile icon Joe Minichino
View More author details

Table of Contents (13) Chapters

Preface Setting Up OpenCV Handling Files, Cameras, and GUIs Processing Images with OpenCV Depth Estimation and Segmentation Detecting and Recognizing Faces Retrieving Images and Searching Using Image Descriptors Building Custom Object Detectors Tracking Objects Camera Models and Augmented Reality Introduction to Neural Networks with OpenCV Other Book You May Enjoy Appendix A: Bending Color Space with the Curves Filter

Edge detection with Canny

OpenCV offers a handy function called Canny (after the algorithm's inventor, John F. Canny), which is very popular not only because of its effectiveness, but also because of the simplicity of its implementation in an OpenCV program since it is a one-liner:

import cv2
import numpy as np

img = cv2.imread("../images/statue_small.jpg", 0)
cv2.imwrite("canny.jpg", cv2.Canny(img, 200, 300)) # Canny in one line!
cv2.imshow("canny", cv2.imread("canny.jpg"))
cv2.waitKey()
cv2.destroyAllWindows()

The result is a very clear identification of the edges:

The Canny edge detection algorithm is complex but also quite interesting. It is a five-step process:

  1. Denoise the image with a Gaussian filter.
  2. Calculate the gradients.
  3. Apply non-maximum suppression (NMS) on the edges. Basically, this means that the algorithm selects the...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}