Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
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
AU$61.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
Paperback Jul 2025 4th Edition
eBook
AU$14.99 AU$49.99
Paperback
AU$61.99
Subscription
Free Trial
Renews at AU$24.99p/m
Arrow left icon
Profile Icon Joseph Howse Profile Icon Joe Minichino
Arrow right icon
Early Access Early Access Publishing in Jul 2025
AU$61.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
Paperback Jul 2025 4th Edition
eBook
AU$14.99 AU$49.99
Paperback
AU$61.99
Subscription
Free Trial
Renews at AU$24.99p/m
eBook
AU$14.99 AU$49.99
Paperback
AU$61.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Australia

Economy delivery 7 - 10 business days

AU$19.95

Product Details

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

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Australia

Economy delivery 7 - 10 business days

AU$19.95

Product Details

Publication date : Jul 31, 2025
Edition : 4th
Language : English
ISBN-13 : 9781803230221
Category :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.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
AU$249.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 AU$5 each
Feature tick icon Exclusive print discounts
AU$349.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 AU$5 each
Feature tick icon Exclusive print discounts
Banner background image

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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela