O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learn OpenCV 4 by Building Projects - Second Edition

Book Description

Explore OpenCV 4 to create visually appealing cross-platform computer vision applications

Key Features

  • Understand basic OpenCV 4 concepts and algorithms
  • Grasp advanced OpenCV techniques such as 3D reconstruction, machine learning, and artificial neural networks
  • Work with Tesseract OCR, an open-source library to recognize text in images

Book Description

OpenCV is one of the best open source libraries available, and can help you focus on constructing complete projects on image processing, motion detection, and image segmentation. Whether you're completely new to computer vision, or have a basic understanding of its concepts, Learn OpenCV 4 by Building Projects – Second edition will be your guide to understanding OpenCV concepts and algorithms through real-world examples and projects.

You'll begin with the installation of OpenCV and the basics of image processing. Then, you'll cover user interfaces and get deeper into image processing. As you progress through the book, you'll learn complex computer vision algorithms and explore machine learning and face detection. The book then guides you in creating optical flow video analysis and background subtraction in complex scenes. In the concluding chapters, you'll also learn about text segmentation and recognition and understand the basics of the new and improved deep learning module.

By the end of this book, you'll be familiar with the basics of Open CV, such as matrix operations, filters, and histograms, and you'll have mastered commonly used computer vision techniques to build OpenCV projects from scratch.

What you will learn

  • Install OpenCV 4 on your operating system
  • Create CMake scripts to compile your C++ application
  • Understand basic image matrix formats and filters
  • Explore segmentation and feature extraction techniques
  • Remove backgrounds from static scenes to identify moving objects for surveillance
  • Employ various techniques to track objects in a live video
  • Work with new OpenCV functions for text detection and recognition with Tesseract
  • Get acquainted with important deep learning tools for image classification

Who this book is for

If you are a software developer with a basic understanding of computer vision and image processing and want to develop interesting computer vision applications with OpenCV, Learn OpenCV 4 by Building Projects for you. Prior knowledge of C++ will help you understand the concepts covered in this book.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Learn OpenCV 4 by Building Projects Second Edition
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the authors
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Code in Action
      4. Conventions used
    4. Get in touch
      1. Reviews
  6. Getting Started with OpenCV
    1. Understanding the human visual system
    2. How do humans understand image content?
      1. Why is it difficult for machines to understand image content?
    3. What can you do with OpenCV?
      1. Inbuilt data structures and input/output
      2. Image processing operations
      3. GUI
      4. Video analysis
      5. 3D reconstruction
      6. Feature extraction
      7. Object detection
      8. Machine learning
      9. Computational photography
      10. Shape analysis
      11. Optical flow algorithms
      12. Face and object recognition
      13. Surface matching
      14. Text detection and recognition
      15. Deep learning
    4. Installing OpenCV
      1. Windows
      2. Mac OS X
      3. Linux
    5. Summary
  7. An Introduction to the Basics of OpenCV
    1. Technical requirements
    2. Basic CMake configuration file
    3. Creating a library
    4. Managing dependencies
    5. Making the script more complex
    6. Images and matrices
    7. Reading/writing images
    8. Reading videos and cameras
    9. Other basic object types
      1. Vec object type
      2. Scalar object type
      3. Point object type
      4. Size object type
      5. Rect object type
      6. RotatedRect object type
    10. Basic matrix operations
    11. Basic data persistence and storage
      1. Writing to FileStorage
    12. Summary
  8. Learning Graphical User Interfaces
    1. Technical requirements
    2. Introducing the OpenCV user interface
    3. Basic graphical user interface with OpenCV
      1. Adding slider and mouse events to our interfaces
    4. Graphic user interface with Qt
      1. Adding buttons to the user interface
    5. OpenGL support
    6. Summary
  9. Delving into Histogram and Filters
    1. Technical requirements
    2. Generating a CMake script file
    3. Creating the graphical user interface
    4. Drawing a histogram
    5. Image color equalization
    6. Lomography effect
    7. Cartoonize effect
    8. Summary
  10. Automated Optical Inspection, Object Segmentation, and Detection
    1. Technical requirements
    2. Isolating objects in a scene
    3. Creating an application for AOI
    4. Preprocessing the input image
      1. Noise removal
      2. Removing the background using the light pattern for segmentation
      3. Thresholding
    5. Segmenting our input image
      1. The connected components algorithm
      2. The findContours algorithm
    6. Summary
  11. Learning Object Classification
    1. Technical requirements
    2. Introducing machine learning concepts
      1. OpenCV machine learning algorithms
    3. Computer vision and the machine learning workflow 
    4. Automatic object inspection classification example
      1. Feature extraction
      2. Training an SVM model
      3. Input image prediction
    5. Summary
  12. Detecting Face Parts and Overlaying Masks
    1. Technical requirements
    2. Understanding Haar cascades
    3. What are integral images?
    4. Overlaying a face mask in a live video
      1. What happened in the code?
    5. Get your sunglasses on
      1. Looking inside the code
    6. Tracking the nose, mouth, and ears
    7. Summary
  13. Video Surveillance, Background Modeling, and Morphological Operations
    1. Technical requirements
    2. Understanding background subtraction
    3. Naive background subtraction
      1. Does it work well?
    4. Frame differencing
      1. How well does it work?
    5. The Mixture of Gaussians approach
      1. What happened in the code?
    6. Morphological image processing
      1. What's the underlying principle?
    7. Slimming the shapes
    8. Thickening the shapes
    9. Other morphological operators
      1. Morphological opening
      2. Morphological closing
      3. Drawing the boundary
      4. Top Hat transform
      5. Black Hat transform
    10. Summary
  14. Learning Object Tracking
    1. Technical requirements
    2. Tracking objects of a specific color
    3. Building an interactive object tracker
    4. Detecting points using the Harris corner detector
    5. Good features to track
    6. Feature-based tracking
      1. Lucas-Kanade method
      2. Farneback algorithm
    7. Summary
  15. Developing Segmentation Algorithms for Text Recognition
    1. Technical requirements
    2. Introducing optical character recognition
    3. Preprocessing stage
      1. Thresholding the image
      2. Text segmentation
        1. Creating connected areas
        2. Identifying paragraph blocks
        3. Text extraction and skewing adjustment
    4. Installing Tesseract OCR on your operating system
      1. Installing Tesseract on Windows
        1. Building the latest library
        2. Setting up Tesseract in Visual Studio
          1. Static linking
      2. Installing Tesseract on Mac
    5. Using the Tesseract OCR library
      1. Creating an OCR function
        1. Sending the output to a file
    6. Summary
  16. Text Recognition with Tesseract
    1. Technical requirements
    2. How the text API works
      1. The scene detection problem
      2. Extremal regions
      3. Extremal region filtering
    3. Using the text API
      1. Text detection
      2. Text extraction
      3. Text recognition
    4. Summary
  17. Deep Learning with OpenCV
    1. Technical requirements
    2. Introduction to deep learning
      1. What is a neural network and how can we learn from data?
      2. Convolutional neural networks
    3. Deep learning in OpenCV
    4. YOLO – real-time object detection
      1. YOLO v3 deep learning model architecture
      2. The YOLO dataset, vocabulary, and model
      3. Importing YOLO into OpenCV
    5. Face detection with SSD
      1. SSD model architecture
      2. Importing SSD face detection into OpenCV
    6. Summary
    7. Further reading
  18. Other Books You May Enjoy
    1. Leave a review – let other readers know what you think