Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning OpenCV 5 Computer Vision with Python
Learning OpenCV 5 Computer Vision with Python

Learning OpenCV 5 Computer Vision with Python: Tackle computer vision and machine learning with the newest tools, techniques and algorithms , Fourth Edition

Arrow left icon
Profile Icon Joseph Howse Profile Icon Joe Minichino
Arrow right icon
Early Access Early Access Publishing in Jul 2025
$24.99 $35.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jul 2025 4th Edition
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Joseph Howse Profile Icon Joe Minichino
Arrow right icon
Early Access Early Access Publishing in Jul 2025
$24.99 $35.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jul 2025 4th Edition
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning OpenCV 5 Computer Vision with Python

Join our book community on Discord

https://discord.gg/djGjeMECxw

You've picked up this book, so you may already have an idea of what OpenCV is. Maybe you have heard of capabilities that seem to come straight out of science fiction, such as training an artificial intelligence model to recognize anything that it sees through a camera. If this is your interest, you will not be disappointed! OpenCV stands for Open Source Computer Vision. It is a free computer vision library that allows you to manipulate images and videos to accomplish a variety of tasks, from displaying frames from a webcam to teaching a robot to recognize real-life objects.

In this book, you will learn how to leverage the immense potential of OpenCV with the Python programming language. Python is an elegant language with a relatively shallow learning curve and very powerful features. This chapter is a quick guide to setting up Python 3, OpenCV 5, and other dependencies. As part of OpenCV, we will set up the opencv_contrib...

Technical requirements

This chapter assumes that you are using one of the following operating systems:

  • Windows 10 or a later version
  • macOS 10.15 (Catalina) or a later version
  • Debian 10 (Buster) or a later version, or a derivative such as the following:
    • Ubuntu 18.04 (Bionic Beaver) or a later version
    • Linux Mint 19 or a later version
  • Arch Linux, or a derivative such as Manjaro

For editing Python scripts and other text files, this book's authors simply recommend that you should have a good text editor. Visual Studio (VS) Code is the most suitable editor because of its simplicity and almost all OS distributions support this editor. Other examples include the following:

  • Notepad++ for Windows
  • BBEdit (free version) for macOS
  • GEdit for the GNOME desktop environment on Linux
  • Kate for the KDE Plasma desktop environment on Linux

We also recommend that you have a Git client installed since this will be the easiest way to obtain the book’s latest sample code, which is hosted on GitHub...

What's new in OpenCV 5

If you are an OpenCV veteran, you might want to know more about OpenCV 5's changes before you decide to install it. Here are some of the highlights:

  • The C++ implementation of OpenCV has been updated to C++14. OpenCV's Python bindings wrap the C++ implementation, so as Python users, we may gain some performance advantages from this update, even though we are not using C++ directly.
  • Support for Python 2 has been dropped because this Python version is obsolete and no longer maintained. If you have any old Python 2 projects, you should upgrade them to Python 3.
  • For many algorithms, support for named parameters has been added in order to make the initialization code more concise and readable.
  • For the pip package installer, the opencv-python and opencv-contrib-python packages are now maintained by the core OpenCV team rather than a third party. The opencv-contrib-python-nonfree package has been discontinued due to patent restrictions.
  • The SIFT algorithm...

Optimizing OpenCV for specific hardware

Generally, the setup instructions in this chapter are compatible with any hardware architecture that is supported by OpenCV and the operating system. For example, the setup instructions that target Linux operating systems will work equally well on x64, x86, ARM, or RISC-V hardware (except that the optional OpenNI package is unavailable for RISC-V).

That said, OpenCV supports many optional optimizations for specific hardware. By following the instructions in this chapter, you will get an OpenCV installation that uses a default set of optimizations for your hardware. The defaults are generally good, but for some applications, you could get even better performance with a more highly customized installation of OpenCV. Here are a few examples of use cases:

  • For x64, x86, or ARM processors, OpenCV can optionally integrate with Intel Thread Building Blocks (TBB), a multithreading library. OpenCV can use TBB to speed up certain parallel algorithms, notably...

Choosing and using the right setup tools

We are free to choose various setup tools depending on our operating system and how much configuration we want to do.

Regardless of the choice of operating system, Python offers some built-in tools that are useful for setting up a development environment. These tools include a package manager called pip and a virtual environment manager called venv. Some of this chapter's instructions will cover pip specifically, but if you would like to learn about venv, please refer to the official Python documentation at https://docs.python.org/3/library/venv.html.

You should consider using venv if you plan to maintain a variety of Python projects that might have conflicting dependencies – for example, projects that depend on different versions of OpenCV. Each of venv's virtual environments has its own set of installed libraries, and we can switch between these environments without reinstalling anything. Within a given virtual environment,...

Running the official sample code

Running a few sample scripts is a good way to test whether OpenCV has been set up correctly. Some samples are included in OpenCV's source code archive. If you have not already obtained the source code, go to https://opencv.org/releases/ and download one of the following archives:

  • For Windows, download the latest archive, labeled Windows. It is a self-extracting ZIP. Run it and, when prompted, enter any destination folder, which we will refer to as <opencv_unzip_destination>. Find the Python samples in <opencv_unzip_destination>/opencv/sources/samples/python.
  • For other systems, download the latest archive, labeled Sources. It is a ZIP file. Unzip it to any destination folder, which we will refer to as <opencv_unzip_destination>. Find the Python samples in <opencv_unzip_destination>/samples/python.

Some of the sample scripts require command-line arguments. However, the following scripts (among others) should work without any...

Finding documentation, help, and updates

OpenCV's documentation can be found at http://docs.opencv.org/, where you can either read it online or download it for offline reading. If you write code on airplanes or other places without internet access, you will definitely want to keep offline copies of the documentation.

The documentation includes a combined API reference for OpenCV's C++ API and its Python API. When you look up a class or function, be sure to read the section under the heading Python.

OpenCV's Python module is named cv2. The 2 in cv2 has nothing to do with the version number of OpenCV; we really are using OpenCV 5. Historically, OpenCV had a cv Python module that wrapped a now-obsolete C version of the library. The cv module was removed in OpenCV 4.

Still, in the official OpenCV 5 samples and in some other authors’ samples, you might see valid Python code such as the following, which imports the cv2 module and gives it a local alias, cv:

import...

Finding this book’s sample code

We will walk through a set of relevant code samples in each chapter of this book. For now, let’s just take note of the samples’ location and format.

All of this book’s samples can be found online in the Git repository at https://github.com/PacktPublishing/Learning-OpenCV-5-Computer-Vision-with-Python-Fourth-Edition/. The contents are organized into various folders by chapter. For some chapters, an interactively editable version of the code is provided as a Juptyer notebook. For example, Chapter 5 has a Jupyter notebook located in the repository at chapter05/chapter05.ipynb.

If you are new to Git or want to expand your Git skills, take a look at the free ebook Pro Git, by Scott Chacon and Ben Straub. You can find it online at https://git-scm.com/book/. The book’s second chapter, Git Basics, is especially helpful for beginners.

Typically, when you start studying a chapter, you might want to pull down the latest code from...

Summary

By now, we should have an OpenCV installation that will serve our needs for the diverse projects described in this book. Depending on which approach we took, we may also have a set of tools and scripts that can be used to reconfigure and rebuild OpenCV for our future needs.

We also know where to find this book’s sample code and OpenCV's official Python samples. The official samples cover a different range of functionalities outside this book's scope, but they are useful as additional learning aids.

In the next chapter, we will familiarize ourselves with the most basic functions of the OpenCV API, namely displaying images and videos, capturing videos through a webcam, and handling basic keyboard and mouse inputs.

Left arrow icon Right arrow icon

Key benefits

  • Build powerful computer vision applications in concise code with OpenCV 5 and Python 3
  • Learn the fundamental concepts of image processing, object classification, and 2D and 3D tracking
  • Train, use, and understand machine learning models, and deploy them in the Cloud

Description

Computer vision is a rapidly evolving science in the field of artificial intelligence, encompassing diverse use cases and techniques. This book will not only help those who are getting started with computer vision but also experts in the domain. You'll be able to put theory into practice by building apps with OpenCV 5 and Python 3. You'll start by setting up OpenCV 5 with Python 3 on various platforms. Next, you'll learn how to perform basic operations such as reading, writing, manipulating, and displaying images, videos, and camera feeds. From taking you through image processing, video analysis, depth estimation, and segmentation, to helping you gain practice by building a GUI app, this book ensures you'll have opportunities for hands-on activities. You'll tackle two popular challenges: face detection and face recognition. You'll also learn about object classification and machine learning, which will enable you to create and use object detectors and even track moving objects in real time. Later, you'll develop your skills in augmented reality and real-world 3D navigation. Finally, you'll cover ANNs and DNNs, learning how to develop apps for recognizing handwritten digits and classifying a person's gender and age, and you'll deploy your solutions to the Cloud. By the end of this book, you'll have the skills you need to execute real-world computer vision projects.

Who is this book for?

This OpenCV book is a good fit for Python programmers who want to get started with computer vision and machine learning. This book will also be useful for Computer vision and AI/ML developers who want to expand their OpenCV skills as well as experts who want to stay up-to-date with OpenCV 5.

What you will learn

  • Install and familiarize yourself with OpenCV 5 s Python 3 bindings
  • Understand image processing and video analysis
  • Use a depth camera to distinguish foreground and background regions
  • Detect and identify objects, and track their motion in videos
  • Train and use your own models to match images and classify objects
  • Detect and recognize faces, and classify their gender and age
  • Build augmented reality applications, and navigate the real 3D world
  • Train neural networks and deploy them as Cloud-based solutions

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 18, 2025
Edition : 4th
Language : English
ISBN-13 : 9781803234250
Category :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 18, 2025
Edition : 4th
Language : English
ISBN-13 : 9781803234250
Category :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Table of Contents

11 Chapters
Learning OpenCV 5 Computer Vision with Python, Fourth Edition: Tackle tools, techniques, and algorithms for computer vision and machine learning Chevron down icon Chevron up icon
Setting Up OpenCV Chevron down icon Chevron up icon
Handling Files, Cameras, and GUIs Chevron down icon Chevron up icon
Processing Images with OpenCV Chevron down icon Chevron up icon
Detecting and Recognizing Faces Chevron down icon Chevron up icon
Retrieving Images and Searching Using Image Descriptors Chevron down icon Chevron up icon
Building Custom Object Detectors Chevron down icon Chevron up icon
Tracking Objects Chevron down icon Chevron up icon
Camera Models and Augmented Reality Chevron down icon Chevron up icon
Introduction to Neural Networks with OpenCV Chevron down icon Chevron up icon
OpenCV Applications at Scale Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Giovanny Sep 25, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good book
Subscriber review Packt
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.