Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning OpenCV 3 Computer Vision with Python (Update)

You're reading from   Learning OpenCV 3 Computer Vision with Python (Update) Unleash the power of computer vision with Python using OpenCV

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785283840
Length 266 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (11) Chapters Close

Preface 1. Setting Up OpenCV FREE CHAPTER 2. Handling Files, Cameras, and GUIs 3. Processing Images with OpenCV 3 4. Depth Estimation and Segmentation 5. Detecting and Recognizing Faces 6. Retrieving Images and Searching Using Image Descriptors 7. Detecting and Recognizing Objects 8. Tracking Objects 9. Neural Networks with OpenCV – an Introduction Index

Edge detection with Canny


OpenCV also offers a very handy function called Canny (after the algorithm's inventor, John F. Canny), which is very popular not only because of its effectiveness, but also the simplicity of its implementation in an OpenCV program, as 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))
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 quite complex but also interesting: it's a five-step process that denoises the image with a Gaussian filter, calculates gradients, applies non maximum suppression (NMS) on edges, a double threshold on all the detected edges to eliminate false positives, and, lastly, analyzes all the edges and their connection to each other to keep the real edges and discard the weak ones.

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 €18.99/month. Cancel anytime