Mastering OpenCV 4 with Python
eBook - ePub

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

  1. 532 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

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

About this book

Create advanced applications with Python and OpenCV, exploring the potential of facial recognition, machine learning, deep learning, web computing and augmented reality.

Key Features

  • 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

Book 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.

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

Who this book is 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.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Mastering OpenCV 4 with Python by Alberto Fernández Villán in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Vision & Pattern Recognition. We have over one million books available in our catalogue for you to explore.

Section 1: Introduction to OpenCV 4 and Python

In this first section of the book, you will be introduced to the OpenCV library. You will learn how to install everything you need to start programming with Python and OpenCV. Also, you will familiarize yourself with the general terminology and concepts to contextualize what you will learn, establishing the foundations you will need in order to grasp the main concepts of this book. Additionally, you will start writing your first scripts in order to get to grips with the OpenCV library, and you will also learn how to work with files and images, which are necessary for building your computer vision applications. Finally, you will see how to draw basic and advanced shapes using the OpenCV library.
The following chapters will be covered in this section:
  • Chapter 1, Setting Up OpenCV
  • Chapter 2, Image Basics in OpenCV
  • Chapter 3, Handling Files and Images
  • Chapter 4, Constructing Basic Shapes in OpenCV

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. At the end of this chapter, you will be able to build your first project involving Python and OpenCV.
The following topics will be covered in this chapter:
  • A theoretical introduction to the OpenCV library
  • Installing Python OpenCV and other packages
  • Running samples, documentation, help, and updates
  • Python and OpenCV project structure
  • First Python and OpenCV project

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/.
Finally, in order to facilitate GitHub activities (for example, cloning a repository), you should install a Git client. In this sense, GitHub provides desktop clients that include the most common repository actions. For an introduction to Git commands, check out https://education.github.com/git-cheat-sheet-education.pdf, where commonly used Git command-line instructions are summarized. Additionally, instructions for installing a Git client on your operating system are included.
The GitHub repository for this book, which contains all the supporting project files necessary to work through the book from the first chapter to the last, can be accessed at https://github.com/PacktPublishing/Mastering-OpenCV-4-with-Python.
Finally, it should be noted that the README file of the GitHub repository for Mastering OpenCV with Python includes the following, which is also attached here for the sake of completeness:
  • Code testing specifications
  • Hardware specifications
  • Related books and products

Code testing specifications

Mastering OpenCV 4 with Python requires some installed packages, which you can see here:
  • Chapter 1, Setting Up OpenCV: opencv-contrib-python
  • Chapter 2, Image Basics in OpenCV: opencv-contrib-python and matplotlib
  • Chapter 3, Handling Files and Images: opencv-contrib-python and matplotlib
  • Chapter 4, Constructing Basic Shapes in OpenCV: opencv-contrib-python and matplotlib
  • Chapter 5, Image Processing Techniques: opencv-contrib-python and matplotlib
  • Chapter 6, Constructing and Building Histograms: opencv-contrib-python and matplotlib
  • Chapter 7, Thresholding Techniques: opencv-contrib-python, matplotlib, scikit-image, and scipy
  • Chapter 8, Contours Detection, Filtering, and Drawing: opencv-contrib-python and matplotlib
  • Chapter 9, Augmented Reality: opencv-contrib-python and matplotlib
  • Chapter 10, Machine Learning with OpenCV: opencv-contrib-python and matplotlib
  • Chapter 11, Face Detection, Tracking, and Recognition: opencv-contrib-python, matplotlib, dlib, face-recognition, cvlib, requests, progressbar, keras, and tensorflow
  • Chapter 12, Introduction to Deep Learning: opencv-contrib-python, matplotlib, tensorflow, and keras
  • Chapter 13, Mobile and Web Computer Vision with Python and OpenCV: opencv-contrib-python, matplotlib, flask, tensorflow, keras, requests, and pillow
Make sure that the version numbers of your installed packages are equal to, or greater than, versions specified here to ensure that the code examples run correctly.
If you want to install the exact versions this book was tested on, include the version when installing from pip, which is indicated as follows.
Run the following command to install the both main and contrib modules:
  • Install opencv-contrib-python:
pip install opencv-contrib-python==4.0.0.21
It should be noted that OpenCV requires numpy. numpy-1.16.1 has been installed when installing opencv-contrib-python==4.0.0.21.
Run the following command to install Matplotlib library:
  • Install matplotlib:
pip install matplo...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. Section 1: Introduction to OpenCV 4 and Python
  7. Setting Up OpenCV
  8. Image Basics in OpenCV
  9. Handling Files and Images
  10. Constructing Basic Shapes in OpenCV
  11. Section 2: Image Processing in OpenCV
  12. Image Processing Techniques
  13. Constructing and Building Histograms
  14. Thresholding Techniques
  15. Contour Detection, Filtering, and Drawing
  16. Augmented Reality
  17. Section 3: Machine Learning and Deep Learning in OpenCV
  18. Machine Learning with OpenCV
  19. Face Detection, Tracking, and Recognition
  20. Introduction to Deep Learning
  21. Section 4: Mobile and Web Computer Vision
  22. Mobile and Web Computer Vision with Python and OpenCV
  23. Assessments
  24. Other Books You May Enjoy