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
Free Learning
Arrow right icon
Mastering OpenCV 4 with Python
Mastering OpenCV 4 with Python

Mastering OpenCV 4 with Python: A practical guide covering topics from image processing, augmented reality to deep learning with OpenCV 4 and Python 3.7

Arrow left icon
Profile Icon Alberto Fernández Villán
Arrow right icon
€20.98 €29.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7 (12 Ratings)
eBook Mar 2019 532 pages 1st Edition
eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Alberto Fernández Villán
Arrow right icon
€20.98 €29.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7 (12 Ratings)
eBook Mar 2019 532 pages 1st Edition
eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

Mastering OpenCV 4 with Python

Setting Up OpenCV

Mastering OpenCV 4 with Python will give you the knowledge to build projects involving Open Source Computer Vision Library (OpenCV) and Python. These two technologies (the first one is a programming language, while the second one is a computer vision and machine learning library) will be introduced. Also, you will learn why the combination of OpenCV and Python has the potential to build every kind of computer application. Finally, an introduction about the main concepts related to the content of this book will be provided.

In this chapter, you will be given step-by-step instructions to install everything you need to start programming with Python and OpenCV. This first chapter is quite long, but do not worry, because it is divided into easily assimilated sections, starting with general terminology and concepts, which assumes that the reader is new to this information...

Technical requirements

This chapter and subsequent chapters are focused on Python (a programming language) and OpenCV (a computer vision library) concepts in connection with computer vision, machine learning, and deep learning techniques (among others). Therefore, Python (https://www.python.org/) and OpenCV (https://opencv.org/) should be installed on your computer. Moreover, some Python packages related to scientific computing and data science should also be installed (for example, NumPy (http://www.numpy.org/) or Matplotlib (https://matplotlib.org/)).

Additionally, it is recommended that you install an integrated development environment (IDE) software package because it facilitates computer programmers with software development. In this sense, a Python-specific IDE is recommended. The de facto Python IDE is PyCharm, which can be downloaded from https://www.jetbrains.com/pycharm...

Understanding Python

Python is an interpreted high-level and general-purpose programming language with a dynamic type system and automatic memory management. The official home of the Python programming language is https://www.python.org/. The popularity of Python has risen steadily over the past decade. This is because Python is a very important programming language in some of today's most exciting and challenging technologies. Artificial intelligence (AI), machine learning, neural networks, deep learning, Internet of Things (IoT), and robotics (among others) rely on Python.

Here are some advantages of Python:

  • Python is considered a perfect language for scientific computing, mainly for four reasons:
    • It is very easy to understand.
    • It has support (via packages) for scientific computing.
    • It removes many of the complexities other programming languages have.
    • It has a simple...

A theoretical introduction to the OpenCV library

OpenCV is a programming library with real-time computer vision capabilities and it is free for both academic and commercial use (BSD license). In this section, an introduction about the OpenCV library will be given, including its main modules and other useful information in connection with the library.

OpenCV modules

OpenCV (since version 2) is divided into several modules, where each module can be understood, in general, as being dedicated to one group of computer vision problems. This division can be seen in the next diagram, where the main modules are shown:


OpenCV modules are shortly described here:

  • core: Core functionality. Core functionality is a module defining basic...

Installing OpenCV, Python, and other packages

OpenCV, Python, and AI-related packages can be installed on most operating systems. We will see how to install these packages by means of different approaches.

Make sure you check out the different installation options before choosing the one that best suits your needs.

Additionally, at the end of this chapter, an introduction to Jupyter Notebook is given due to the popularity of these documents, which can be run to perform data analysis.

Installing Python, OpenCV, and other packages globally

In this section, you will see how to install Python, OpenCV, and any other package globally. Specific instructions are given for both Linux and Windows operating systems.

...

Installing Python, OpenCV, and other packages with virtualenv

virtualenv (https://pypi.org/project/virtualenv/) is a very popular tool that creates isolated Python environments for Python libraries. virtualenv allows multiple Python projects that have different (and sometimes conflicting) requirements. In a technical way, virtualenv works by installing some files under a directory (for example, env/).

Additionally, virtualenv modifies the PATH environment variable to prefix it with a custom bin directory (for example, env/bin/). Additionally, an exact copy of the Python or Python3 binary is placed in this directory. Once this virtual environment is activated, you can install packages in the virtual environment using pip. virtualenv is also recommended by the PyPA (https://packaging.python.org/guides/tool-recommendations/). Therefore, we will see how to install OpenCV or any other...

Python IDEs to create virtual environments with virtualenv

In the next section, we are going to create virtual environments with PyCharm, which is a Python IDE. But before doing that, we are going to discuss IDEs. An IDE is a software application that facilitates computer programmers with software development. IDEs present a single program where all the development is done. In connection with Python IDEs, two approaches can be found:

  • General editors and IDEs with Python support
  • Python-specific editors and IDEs

In the first category (general IDEs), some examples should be highlighted:

  • Eclipse + PyDev
  • Visual Studio + Python Tools for Visual Studio
  • Atom + Python extension

In the second category, here are some Python-specific IDEs:

  • PyCharm: One of the best full-featured, dedicated IDEs for Python. PyCharm installs quickly and easily on Windows, macOS, and Linux platforms...

Anaconda/Miniconda distributions and conda package–and environment-management system

Conda (https://conda.io/docs/) is an open source package-management and environment-management system (provides virtual environment capabilities) that runs on many operating systems (for example, Windows, macOS, and Linux). Conda installs, runs, and updates packages and their dependencies. Conda can create, save, load, and switch between environments.

As conda is included in all versions of Anaconda and Miniconda, you should have already installed Anaconda or Miniconda.

Anaconda is a downloadable, free, open source, high-performance Python and R distribution. Anaconda comes with conda, conda build, Python, and more than 100 open source scientific packages and their dependencies. Using the conda install command, you can easily install popular open source packages for data science from...

Packages for scientific computing, data science, machine learning, deep learning, and computer vision

So far, we have seen how to install Python, OpenCV, and a few other packages (numpy and matplotlib) from scratch, or using Anaconda distribution, which includes many popular data-science packages. In this way, some knowledge about the main packages for scientific computing, data science, machine learning, and computer vision is a key point because they offer powerful computational tools. Throughout this book, many Python packages will be used. Not all of the cited packages in this section will, but a comprehensive list is provided for the sake of completeness in order to show the potential of Python in topics related to the content of this book:

  • NumPy (http://www.numpy.org/) provides support for large, multi-dimensional arrays. NumPy is a key library in computer vision because...

Jupyter Notebook

The Jupyter Notebook an open source web application that allows you to edit and run documents via a web browser. These documents, which are called Notebook documents (or notebooks), contain code (more than 40 programming languages, including Python, are supported) and rich text elements (paragraphs, equations, figures). The Jupyter Notebook can be executed on a local computer or can be installed on a remote server. You can start with notebooks, trying them online or installing the Jupyter Notebook.

Trying Jupiter Notebook online

First, go to https://jupyter.org/try. You will see something like this:


To try Jupyter with Python online, click on the Python option, or paste this URL into your web browser: https...

The OpenCV and Python project structure

The project structure is the way you organize all the files inside a folder in a way that the project best accomplishes the objectives. We are going to start with a .py script (sampleproject.py) that should be with other files in order to complete the information about this script dependencies, license, how to install it, or how to test it. A common approach for structuring this basic project is as follows:

sampleproject/

├── .gitignore
├── sampleproject.py
├── LICENSE
├── README.rst
├── requirements.txt
├── setup.py
└── tests.py

sampleproject.py—if your project is only a single Python source file, then put it into the directory and name it something related to your project.

...

Our first Python and OpenCV project

Based on the minimal project structure that was shown in the previous section, we are going to create our first Python and OpenCV project. This project has the following structure:

helloopencv/

├── images/

├── .gitignore
├── helloopencv.py
├── LICENSE
├── README.rst
├── requirements.txt
├── setup.py
└── helloopencvtests.py

README.rst (.rst extension) follows a basic structure, which was shown in the previous section. Python and ReStructuredText (RST) are deeply linked—RST is the format of docutils and sphinx (the de facto standard for documenting python code). RST is used both to document objects via docstrings, and to write additional documentation. If you go to...

Summary

In this first chapter, we covered the main steps to set up OpenCV and Python to build your computer vision projects. At the beginning of this chapter, we quickly looked at the main concepts in this book Artificial Intelligence, machine learning, neural networks, and deep learning. Then we explored the OpenCV library, including the history of the library and its main modules. As OpenCV and other packages can be installed in many operating systems and in different ways, we covered the main approaches.

Specifically, we saw how to install Python, OpenCV, and other packages globally or in a virtual environment. In connection with the installation of the packages, we introduced Anaconda/Miniconda and Conda, because we can also create and manage virtual environments. Additionally, Anaconda/Miniconda comes with many open source scientific packages, including SciPy and...

Questions

  1. What is a virtual environment?
  2. What is the connection between pip, virtualenv, pipenv, Anaconda, and conda?
  3. What is the Jupyter Notebook?
  4. What are the main packages to work with computer vision in Python?
  5. What does pip install -r requirements.txt do?
  6. What is an IDE and why should you use one during the development of your projects?
  7. Under what license is OpenCV published?

Further reading

The following references will help you dive deeper into concepts presented in this chapter:

Check out these references (mainly books) for more information on concepts that will be presented in future chapters of the book. Keep this list handy; it will be really helpful:

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Develop your computer vision skills by mastering algorithms in Open Source Computer Vision 4 (OpenCV 4) and Python
  • Apply machine learning and deep learning techniques with TensorFlow and Keras
  • Discover the modern design patterns you should avoid when developing efficient computer vision applications

Description

OpenCV is considered to be one of the best open source computer vision and machine learning software libraries. It helps developers build complete projects in relation to image processing, motion detection, or image segmentation, among many others. OpenCV for Python enables you to run computer vision algorithms smoothly in real time, combining the best of the OpenCV C++ API and the Python language. In this book, you'll get started by setting up OpenCV and delving into the key concepts of computer vision. You'll then proceed to study more advanced concepts and discover the full potential of OpenCV. The book will also introduce you to the creation of advanced applications using Python and OpenCV, enabling you to develop applications that include facial recognition, target tracking, or augmented reality. Next, you'll learn machine learning techniques and concepts, understand how to apply them in real-world examples, and also explore their benefits, including real-time data production and faster data processing. You'll also discover how to translate the functionality provided by OpenCV into optimized application code projects using Python bindings. Toward the concluding chapters, you'll explore the application of artificial intelligence and deep learning techniques using the popular Python libraries TensorFlow, and Keras. By the end of this book, you'll be able to develop advanced computer vision applications to meet your customers' demands.

Who is this book for?

This book is designed for computer vision developers, engineers, and researchers who want to develop modern computer vision applications. Basic experience of OpenCV and Python programming is a must.

What you will learn

  • Handle files and images, and explore various image processing techniques
  • Explore image transformations, including translation, resizing, and cropping
  • Gain insights into building histograms
  • Brush up on contour detection, filtering, and drawing
  • Work with Augmented Reality to build marker-based and markerless applications
  • Work with the main machine learning algorithms in OpenCV
  • Explore the deep learning Python libraries and OpenCV deep learning capabilities
  • Create computer vision and deep learning web applications

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 29, 2019
Length: 532 pages
Edition : 1st
Language : English
ISBN-13 : 9781789349757
Vendor :
Intel
Category :
Languages :
Tools :

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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 29, 2019
Length: 532 pages
Edition : 1st
Language : English
ISBN-13 : 9781789349757
Vendor :
Intel
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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

Frequently bought together


Stars icon
Total 102.97
OpenCV 4 for Secret Agents
€32.99
OpenCV 4 Computer Vision Application Programming Cookbook
€32.99
Mastering OpenCV 4 with Python
€36.99
Total 102.97 Stars icon
Banner background image

Table of Contents

19 Chapters
Section 1: Introduction to OpenCV 4 and Python Chevron down icon Chevron up icon
Setting Up OpenCV Chevron down icon Chevron up icon
Image Basics in OpenCV Chevron down icon Chevron up icon
Handling Files and Images Chevron down icon Chevron up icon
Constructing Basic Shapes in OpenCV Chevron down icon Chevron up icon
Section 2: Image Processing in OpenCV Chevron down icon Chevron up icon
Image Processing Techniques Chevron down icon Chevron up icon
Constructing and Building Histograms Chevron down icon Chevron up icon
Thresholding Techniques Chevron down icon Chevron up icon
Contour Detection, Filtering, and Drawing Chevron down icon Chevron up icon
Augmented Reality Chevron down icon Chevron up icon
Section 3: Machine Learning and Deep Learning in OpenCV Chevron down icon Chevron up icon
Machine Learning with OpenCV Chevron down icon Chevron up icon
Face Detection, Tracking, and Recognition Chevron down icon Chevron up icon
Introduction to Deep Learning Chevron down icon Chevron up icon
Section 4: Mobile and Web Computer Vision Chevron down icon Chevron up icon
Mobile and Web Computer Vision with Python and OpenCV Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(12 Ratings)
5 star 50%
4 star 16.7%
3 star 0%
2 star 16.7%
1 star 16.7%
Filter icon Filter
Top Reviews

Filter reviews by




Wayne Duquaine Jan 20, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Lukas Sliacky Jul 05, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Manés Sep 18, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am an Electronic Engineer but not a specialist in image processing. I purchased the book because know I need to work on image processing applied to some branches of research in electrical Engineering. I did really like the book since it is practical and accessible. It is possible to get introduced in the field of image processing as well as to dive into more complex applications including machine learning. The use of Python combined with examples makes the learning curve fast, and the reader can choose the level of the depth or the field of application more suitable to his/her needs.Therefore, I think this book can be used by anyone with a very basic knowledge of image processing or someone with expertise in the field that wants to get practical information for any specific field. I do recommend it.
Amazon Verified review Amazon
Xolmatic Jun 25, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Queria tener un libro que hablase de OpenCV 4.0 y este es sencillamente genial, esta estructurado de una manera correcta, con un avance en el temario que hace que sea muy facil su lectura. Ne gusta su maquetacion, contenido... espero que su autor se aventure a escribir mas obras relacionadas. Me parece muy recomendable.
Amazon Verified review Amazon
Valentine Dvorovkin Jul 31, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very good book. I immediately downloaded all code, so I can see how it works.Very good explanation inside book text + WORKING CODE, that shows in OpenCV and Matplotlib - Images, Histograms - RGB and Gray, binarization, Thresholding methods and results + face detecting and deep learning with OpenCV, TensorFlow etc. If you are starter - highly recommend.
Amazon Verified review Amazon
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.