You are previewing Learning OpenCV 3 Computer Vision with Python - Second Edition.
O'Reilly logo
Learning OpenCV 3 Computer Vision with Python - Second Edition

Book Description

Unleash the power of computer vision with Python using OpenCV

About This Book

  • Create impressive applications with OpenCV and Python

  • Familiarize yourself with advanced machine learning concepts

  • Harness the power of computer vision with this easy-to-follow guide

  • Who This Book Is For

    Intended for novices to the world of OpenCV and computer vision, as well as OpenCV veterans that want to learn about what's new in OpenCV 3, this book is useful as a reference for experts and a training manual for beginners, or for anybody who wants to familiarize themselves with the concepts of object classification and detection in simple and understandable terms. Basic knowledge about Python and programming concepts is required, although the book has an easy learning curve both from a theoretical and coding point of view.

    What You Will Learn

  • Install and familiarize yourself with OpenCV 3's Python API

  • Grasp the basics of image processing and video analysis

  • Identify and recognize objects in images and videos

  • Detect and recognize faces using OpenCV

  • Train and use your own object classifiers

  • Learn about machine learning concepts in a computer vision context

  • Work with artificial neural networks using OpenCV

  • Develop your own computer vision real-life application

  • In Detail

    OpenCV 3 is a state-of-the-art computer vision library that allows a great variety of image and video processing operations. Some of the more spectacular and futuristic features such as face recognition or object tracking are easily achievable with OpenCV 3. Learning the basic concepts behind computer vision algorithms, models, and OpenCV's API will enable the development of all sorts of real-world applications, including security and surveillance.

    Starting with basic image processing operations, the book will take you through to advanced computer vision concepts. Computer vision is a rapidly evolving science whose applications in the real world are exploding, so this book will appeal to computer vision novices as well as experts of the subject wanting to learn the brand new OpenCV 3.0.0. You will build a theoretical foundation of image processing and video analysis, and progress to the concepts of classification through machine learning, acquiring the technical know-how that will allow you to create and use object detectors and classifiers, and even track objects in movies or video camera feeds. Finally, the journey will end in the world of artificial neural networks, along with the development of a hand-written digits recognition application.

    Style and approach

    This book is a comprehensive guide to the brand new OpenCV 3 with Python to develop real-life computer vision applications.

    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 If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning OpenCV 3 Computer Vision with Python Second Edition
      1. Table of Contents
      2. Learning OpenCV 3 Computer Vision with Python Second Edition
      3. Credits
      4. About the Authors
      5. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Setting Up OpenCV
        1. Choosing and using the right setup tools
          1. Installation on Windows
            1. Using binary installers (no support for depth cameras)
            2. Using CMake and compilers
          2. Installing on OS X
            1. Using MacPorts with ready-made packages
            2. Using MacPorts with your own custom packages
            3. Using Homebrew with ready-made packages (no support for depth cameras)
            4. Using Homebrew with your own custom packages
          3. Installation on Ubuntu and its derivatives
            1. Using the Ubuntu repository (no support for depth cameras)
            2. Building OpenCV from a source
          4. Installation on other Unix-like systems
        2. Installing the Contrib modules
        3. Running samples
        4. Finding documentation, help, and updates
        5. Summary
      9. 2. Handling Files, Cameras, and GUIs
        1. Basic I/O scripts
          1. Reading/writing an image file
          2. Converting between an image and raw bytes
          3. Accessing image data with numpy.array
          4. Reading/writing a video file
          5. Capturing camera frames
          6. Displaying images in a window
          7. Displaying camera frames in a window
        2. Project Cameo (face tracking and image manipulation)
        3. Cameo – an object-oriented design
          1. Abstracting a video stream with managers.CaptureManager
          2. Abstracting a window and keyboard with managers.WindowManager
          3. Applying everything with cameo.Cameo
        4. Summary
      10. 3. Processing Images with OpenCV 3
        1. Converting between different color spaces
          1. A quick note on BGR
        2. The Fourier Transform
          1. High pass filter
          2. Low pass filter
        3. Creating modules
        4. Edge detection
        5. Custom kernels – getting convoluted
        6. Modifying the application
        7. Edge detection with Canny
        8. Contour detection
        9. Contours – bounding box, minimum area rectangle, and minimum enclosing circle
        10. Contours – convex contours and the Douglas-Peucker algorithm
        11. Line and circle detection
          1. Line detection
          2. Circle detection
        12. Detecting shapes
        13. Summary
      11. 4. Depth Estimation and Segmentation
        1. Creating modules
        2. Capturing frames from a depth camera
        3. Creating a mask from a disparity map
        4. Masking a copy operation
        5. Depth estimation with a normal camera
        6. Object segmentation using the Watershed and GrabCut algorithms
          1. Example of foreground detection with GrabCut
          2. Image segmentation with the Watershed algorithm
        7. Summary
      12. 5. Detecting and Recognizing Faces
        1. Conceptualizing Haar cascades
        2. Getting Haar cascade data
        3. Using OpenCV to perform face detection
          1. Performing face detection on a still image
          2. Performing face detection on a video
          3. Performing face recognition
            1. Generating the data for face recognition
            2. Recognizing faces
            3. Preparing the training data
            4. Loading the data and recognizing faces
            5. Performing an Eigenfaces recognition
            6. Performing face recognition with Fisherfaces
            7. Performing face recognition with LBPH
            8. Discarding results with confidence score
        4. Summary
      13. 6. Retrieving Images and Searching Using Image Descriptors
        1. Feature detection algorithms
          1. Defining features
            1. Detecting features – corners
          2. Feature extraction and description using DoG and SIFT
            1. Anatomy of a keypoint
          3. Feature extraction and detection using Fast Hessian and SURF
          4. ORB feature detection and feature matching
            1. FAST
            2. BRIEF
            3. Brute-Force matching
          5. Feature matching with ORB
          6. Using K-Nearest Neighbors matching
          7. FLANN-based matching
          8. FLANN matching with homography
          9. A sample application – tattoo forensics
            1. Saving image descriptors to file
            2. Scanning for matches
        2. Summary
      14. 7. Detecting and Recognizing Objects
        1. Object detection and recognition techniques
          1. HOG descriptors
            1. The scale issue
            2. The location issue
              1. Image pyramid
              2. Sliding windows
            3. Non-maximum (or non-maxima) suppression
            4. Support vector machines
          2. People detection
          3. Creating and training an object detector
            1. Bag-of-words
            2. BOW in computer vision
              1. The k-means clustering
        2. Detecting cars
          1. What did we just do?
          2. SVM and sliding windows
            1. Example – car detection in a scene
              1. Examining
              2. Associating training data with classes
            2. Dude, where's my car?
        3. Summary
      15. 8. Tracking Objects
        1. Detecting moving objects
          1. Basic motion detection
        2. Background subtractors – KNN, MOG2, and GMG
          1. Meanshift and CAMShift
          2. Color histograms
            1. The calcHist function
            2. The calcBackProject function
            3. In summary
          3. Back to the code
        3. CAMShift
        4. The Kalman filter
          1. Predict and update
          2. An example
          3. A real-life example – tracking pedestrians
            1. The application workflow
            2. A brief digression – functional versus object-oriented programming
          4. The Pedestrian class
          5. The main program
            1. Where do we go from here?
        5. Summary
      16. 9. Neural Networks with OpenCV – an Introduction
        1. Artificial neural networks
          1. Neurons and perceptrons
        2. The structure of an ANN
          1. Network layers by example
            1. The input layer
            2. The output layer
            3. The hidden layer
              1. The learning algorithms
        3. ANNs in OpenCV
          1. ANN-imal classification
          2. Training epochs
        4. Handwritten digit recognition with ANNs
          1. MNIST – the handwritten digit database
          2. Customized training data
          3. The initial parameters
            1. The input layer
            2. The hidden layer
            3. The output layer
          4. Training epochs
          5. Other parameters
          6. Mini-libraries
          7. The main file
        5. Possible improvements and potential applications
          1. Improvements
            1. Potential applications
        6. Summary
          1. To boldly go…
      17. Index