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

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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 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, and 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 Python. 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 understanding advanced concepts and even discovering the full potential of OpenCV. The book will gradually introduce you to the creation of advanced applications using Python and OpenCV, enabling you to develop apps that include facial recognition, target tracking, and 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, such as real-time data production and faster data processing. As you progress, you'll discover how to translate the functionality provided by OpenCV into optimized application code projects using Python bindings. In the concluding chapters, you'll get to grips with 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 confidently develop advanced computer vision applications to meet your customers' demands. What you will • Handle files and images, and explore a variety of image processing techniques • Understand 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 • Explore deep learning Python libraries and OpenCV capabilities • Work with the important machine learning algorithms in OpenCV • 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. About the Author Alberto Fernández Villán is a software engineer with more than 12 years of experience in developing innovative solutions. In the last couple of years, he has been working in various projects related to monitoring systems for industrial plants, applying both Internet of Things (IoT) and big data technologies. He has a Ph.D. in computer vision (2017), a deep learning certification (2018), and several publications in connection with computer vision and machine learning in journals such as Machine Vision and Applications, IEEE Transactions on Industrial Informatics, Sensors, IEEE Transactions on Industry Applications, IEEE Latin America Transactions, and more. As of 2013, he is a registered and active user (albertofernandez) on the Q&A OpenCV forum.

Author(s): Alberto Fernandez Villan
Edition: 1
Publisher: Packt Publishing
Year: 2019

Language: English
Commentary: Vector PDF
Pages: 532
City: Birmingham, UK
Tags: Machine Learning; Deep Learning; Computer Vision; Video; Image Processing; OpenCV; Python; Face Recognition; Web Applications; Image Recognition; Keras; TensorFlow; Augmented Reality; Image Morphing; Image Segmentation; Mobile Applications

Cover
Title Page
Copyright and Credits
About Packt
Contributors
Table of Contents
Preface
Section 1: Introduction to OpenCV 4 and Python
Chapter 1: Setting Up OpenCV
Technical requirements
Code testing specifications
Hardware specifications
Understanding Python
Introducing OpenCV
Contextualizing the reader
A theoretical introduction to the OpenCV library
OpenCV modules
OpenCV users
OpenCV applications
Why citing OpenCV in your research work
Installing OpenCV, Python, and other packages
Installing Python, OpenCV, and other packages globally
Installing Python
Installing Python on Linux
Installing Python on Windows
Installing OpenCV
Installing OpenCV on Linux
Installing OpenCV on Windows
Testing the installation
Installing Python, OpenCV, and other packages with virtualenv
Python IDEs to create virtual environments with virtualenv
Anaconda/Miniconda distributions and conda package–and environment-management system 
Packages for scientific computing, data science, machine learning, deep learning, and computer vision
Jupyter Notebook
Trying Jupiter Notebook online 
Installing the Jupyter Notebook
Installing Jupyter using Anaconda
Installing Jupyter with pip
The OpenCV and Python project structure
Our first Python and OpenCV project
Summary
Questions
Further reading
Chapter 2: Image Basics in OpenCV
Technical requirements
A theoretical introduction to image basics
Main problems in image processing
Image-processing steps
Images formulation
Concepts of pixels, colors, channels, images, and color spaces
File extensions
The coordinate system in OpenCV
Accessing and manipulating pixels in OpenCV
Accessing and manipulating pixels in OpenCV with BGR images
Accessing and manipulating pixels in OpenCV with grayscale images
BGR order in OpenCV
Summary
Questions
Further reading
Chapter 3: Handling Files and Images
Technical requirements
An introduction to handling files and images
sys.argv
Argparse – command-line option and argument parsing
Reading and writing images
Reading images in OpenCV
Reading and writing images in OpenCV
Reading camera frames and video files
Reading camera frames
Accessing some properties of the capture object
Saving camera frames
Reading a video file
Reading from an IP camera
Writing a video file
Calculating frames per second
Considerations for writing a video file
Playing with video capture properties
Getting all the properties from the video capture object
Using the properties – playing a video backwards
Summary
Questions
Further reading
Chapter 4: Constructing Basic Shapes in OpenCV
Technical requirements
A theoretical introduction to drawing in OpenCV
Drawing shapes
Basic shapes – lines, rectangles, and circles
Drawing lines
Drawing rectangles
Drawing circles
Understanding advanced shapes
Drawing a clip line
Drawing arrows
Drawing ellipses
Drawing polygons
Shift parameter in drawing functions
lineType parameter in drawing functions
Writing text
Drawing text
Using all OpenCV text fonts
More functions related to text
Dynamic drawing with mouse events
Drawing dynamic shapes
Drawing both text and shapes
Event handling with Matplotlib
Advanced drawing
Summary
Questions
Further reading
Section 2: Image Processing in OpenCV
Chapter 5: Image Processing Techniques
Technical requirements
Splitting and merging channels in OpenCV
Geometric transformations of images
Scaling an image
Translating an image
Rotating an image
Affine transformation of an image
Perspective transformation of an image
Cropping an image
Image filtering
Applying arbitrary kernels
Smoothing images
Averaging filter
Gaussian filtering
Median filtering
Bilateral filtering
Sharpening images
Common kernels in image processing
Creating cartoonized images
Arithmetic with images
Saturation arithmetic
Image addition and subtraction
Image blending
Bitwise operations
Morphological transformations
Dilation operation
Erosion operation
Opening operation
Closing operation
Morphological gradient operation
Top hat operation
Black hat operation
Structuring element
Applying morphological transformations to images
Color spaces
Showing color spaces
Skin segmentation in different color spaces
Color maps
Color maps in OpenCV
Custom color maps
Showing the legend for the custom color map
Summary
Questions
Further reading
Chapter 6: Constructing and Building Histograms
Technical requirements
A theoretical introduction to histograms
Histogram terminology
Grayscale histograms
Grayscale histograms without a mask
Grayscale histograms with a mask
Color histograms
Custom visualizations of histograms
Comparing OpenCV, NumPy, and Matplotlib histograms
Histogram equalization
Grayscale histogram equalization
Color histogram equalization
Contrast Limited Adaptive Histogram Equalization 
Comparing CLAHE and histogram equalization
Histogram comparison
Summary
Questions
Further reading
Chapter 7: Thresholding Techniques
Technical requirements
Installing scikit-image
Installing SciPy
Introducing thresholding techniques
Simple thresholding 
Thresholding types
Simple thresholding applied to a real image
Adaptive thresholding
Otsu's thresholding algorithm
The triangle binarization algorithm
Thresholding color images
Thresholding algorithms using scikit-image
Introducing thresholding with scikit-image
Trying out more thresholding techniques with scikit-image
Summary
Questions
Further reading
Chapter 8: Contour Detection, Filtering, and Drawing
Technical requirements
An introduction to contours
Compressing contours
Image moments
Some object features based on moments
Hu moment invariants
Zernike moments
More functionality related to contours
Filtering contours
Recognizing contours
Matching contours
Summary
Questions
Further reading
Chapter 9: Augmented Reality
Technical requirements
An introduction to augmented reality
Markerless-based augmented reality
Feature detection
Feature matching
Feature matching and homography computation to find objects
Marker-based augmented reality
Creating markers and dictionaries
Detecting markers
Camera calibration
Camera pose estimation
Camera pose estimation and basic augmentation
Camera pose estimation and more advanced augmentation
Snapchat-based augmented reality
Snapchat-based augmented reality OpenCV moustache overlay
Snapchat-based augmented reality OpenCV glasses overlay
QR code detection
Summary
Questions
Further reading
Section 3: Machine Learning and Deep Learning in OpenCV
Chapter 10: Machine Learning with OpenCV
Technical requirements
An introduction to machine learning
Supervised machine learning
Unsupervised machine learning
Semi-supervised machine learning
k-means clustering
Understanding k-means clustering
Color quantization using k-means clustering
k-nearest neighbor
Understanding k-nearest neighbors
Recognizing handwritten digits using k-nearest neighbor 
Support vector machine
Understanding SVM
Handwritten digit recognition using SVM
Summary
Questions
Further reading
Chapter 11: Face Detection, Tracking, and Recognition
Technical requirements
Installing dlib
Installing the face_recognition package
Installing the cvlib package
Face processing introduction
Face detection
Face detection with OpenCV
Face detection with dlib
Face detection with face_recognition
Face detection with cvlib
Detecting facial landmarks
Detecting facial landmarks with OpenCV
Detecting facial landmarks with dlib
Detecting facial landmarks with face_recognition
Face tracking
Face tracking with the dlib DCF-based tracker
Object tracking with the dlib DCF-based tracker
Face recognition
Face recognition with OpenCV
Face recognition with dlib
Face recognition with face_recognition
Summary
Questions
Further reading
Chapter 12: Introduction to Deep Learning
Technical requirements
Installing TensorFlow
Installing Keras
Deep learning overview for computer vision tasks
Deep learning characteristics
Deep learning explosion
Deep learning for image classification
Deep learning for object detection 
Deep learning in OpenCV
Understanding cv2.dnn.blobFromImage()
Complete examples using the OpenCV DNN face detector
OpenCV deep learning classification
AlexNet for image classification
GoogLeNet for image classification
ResNet for image classification
SqueezeNet for image classification
OpenCV deep learning object detection
MobileNet-SSD for object detection
YOLO for object detection
The TensorFlow library
Introduction example to TensorFlow
Linear regression in TensorFlow
Handwritten digits recognition using TensorFlow
The Keras library
Linear regression in Keras
Handwritten digit recognition in Keras
Summary
Questions
Further reading
Section 4: Mobile and Web Computer Vision
Chapter 13: Mobile and Web Computer Vision with Python and OpenCV
Technical requirements
Installing the packages
Introduction to Python web frameworks
Introduction to Flask
Web computer vision applications using OpenCV and Flask
A minimal example to introduce OpenCV and Flask 
Minimal face API using OpenCV
Deep learning cat detection API using OpenCV
Deep learning API using Keras and Flask
Keras applications
Deep learning REST API using Keras Applications
Deploying a Flask application to the cloud
Summary
Questions
Further reading
Assessments
Other Books You May Enjoy
Index