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 5 Computer Vision with Python

You're reading from   Learning OpenCV 5 Computer Vision with Python Tackle computer vision and machine learning with the newest tools, techniques and algorithms

Arrow left icon
Product type Paperback
Published in Jul 2025
Publisher Packt
ISBN-13 9781803230221
Length
Edition 4th Edition
Arrow right icon
Authors (2):
Arrow left icon
Joe Minichino Joe Minichino
Author Profile Icon Joe Minichino
Joe Minichino
Joseph Howse Joseph Howse
Author Profile Icon Joseph Howse
Joseph Howse
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

1. Learning OpenCV 5 Computer Vision with Python, Fourth Edition: Tackle tools, techniques, and algorithms for computer vision and machine learning FREE CHAPTER
2. Setting Up OpenCV 3. Handling Files, Cameras, and GUIs 4. Processing Images with OpenCV 5. Detecting and Recognizing Faces 6. Retrieving Images and Searching Using Image Descriptors 7. Building Custom Object Detectors 8. Tracking Objects 9. Camera Models and Augmented Reality 10. Introduction to Neural Networks with OpenCV 11. OpenCV Applications at Scale Appendix A: Bending Color Space with the Curves Filter

Contour detection

A vital task in computer vision is contour detection. We want to detect contours or outlines of subjects contained in an image or video frame, not only as an end in itself but also as a step toward other operations. These operations are, namely, computing bounding polygons, approximating shapes, and generally calculating regions of interest (ROIs). ROIs considerably simplify interaction with image data because a rectangular region in NumPy is easily defined with an array slice. We will be using contour detection and ROIs a lot when we explore the concepts of object detection (including face detection) and object tracking in later chapters.

Let's familiarize ourselves with the contour detection API via an example:

import cv2
import numpy as np
img = np.zeros((200, 200), dtype=np.uint8)
img[50:150, 50:150] = 255
ret, thresh = cv2.threshold(img, 127, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                       cv2.CHAIN_APPROX_SIMPLE...
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