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

OpenCV 3 Computer Vision with Python Cookbook

Book Description

Recipe-based approach to tackle the most common problems in Computer Vision by leveraging the functionality of OpenCV using Python APIs

About This Book

  • Build computer vision applications with OpenCV functionality via Python API
  • Get to grips with image processing, multiple view geometry, and machine learning
  • Learn to use deep learning models for image classification, object detection, and face recognition

Who This Book Is For

This book is for developers who have a basic knowledge of Python. If you are aware of the basics of OpenCV and are ready to build computer vision systems that are smarter, faster, more complex, and more practical than the competition, then this book is for you.

What You Will Learn

  • Get familiar with low-level image processing methods
  • See the common linear algebra tools needed in computer vision
  • Work with different camera models and epipolar geometry
  • Find out how to detect interesting points in images and compare them
  • Binarize images and mask out regions of interest
  • Detect objects and track them in videos

In Detail

OpenCV 3 is a native cross-platform library for computer vision, machine learning, and image processing. OpenCV's convenient high-level APIs hide very powerful internals designed for computational efficiency that can take advantage of multicore and GPU processing. This book will help you tackle increasingly challenging computer vision problems by providing a number of recipes that you can use to improve your applications.

In this book, you will learn how to process an image by manipulating pixels and analyze an image using histograms. Then, we'll show you how to apply image filters to enhance image content and exploit the image geometry in order to relay different views of a pictured scene. We'll explore techniques to achieve camera calibration and perform a multiple-view analysis.

Later, you'll work on reconstructing a 3D scene from images, converting low-level pixel information to high-level concepts for applications such as object detection and recognition. You'll also discover how to process video from files or cameras and how to detect and track moving objects. Finally, you'll get acquainted with recent approaches in deep learning and neural networks.

By the end of the book, you'll be able to apply your skills in OpenCV to create computer vision applications in various domains.

Style and approach

This book helps you learn the core concepts of OpenCV faster by taking a recipe-based approach where you can try out different code snippets to understand a concept.

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. OpenCV 3 Computer Vision with Python Cookbook
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the authors
    2. About the reviewer
    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. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Get in touch
      1. Reviews
  6. I/O and GUI
    1. Introduction
    2. Reading images from files
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Simple image transformations—resizing and flipping
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Saving images using lossy and lossless compression
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Showing images in an OpenCV window
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Working with UI elements, such as buttons and trackbars, in an OpenCV window
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Drawing 2D primitives—markers, lines, ellipses, rectangles, and text
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Handling user input from a keyboard
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Making your app interactive through handling user input from a mouse
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Capturing and showing frames from a camera
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Playing frame stream from video
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Obtaining a frame stream properties
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Writing a frame stream into video
      1. Getting ready
      2. How to do it...
      3. How it works...
    14. Jumping between frames in video files
      1. Getting ready
      2. How to do it...
      3. How it works...
  7. Matrices, Colors, and Filters
    1. Introduction
    2. Manipulating matrices-creating, filling, accessing elements, and ROIs
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Converting between different data types and scaling values
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Non-image data persistence using NumPy
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Manipulating image channels
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Converting images from one color space to another
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Gamma correction and per-element math
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Mean/variance image normalization
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Computing image histograms
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Equalizing image histograms
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Removing noise using Gaussian, median, and bilateral filters
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Computing gradients using Sobel operator
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Creating and applying your own filter
      1. Getting ready
      2. How to do it...
      3. How it works...
    14. Processing images with real-valued Gabor filters
      1. Getting ready
      2. How to do it...
      3. How it works...
    15. Going from the spatial domain to the frequency domain (and back) using the discrete Fourier transform
      1. Getting ready
      2. How to do it...
      3. How it works...
    16. Manipulating image frequencies for image filtration
      1. Getting ready
      2. How to do it...
      3. How it works...
    17. Processing images with different thresholds
      1. Getting ready
      2. How to do it...
      3. How it works...
    18. Morphological operators
      1. Getting ready
      2. How to do it...
      3. How it works...
    19. Image masks and binary operations
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Contours and Segmentation
    1. Introduction
    2. Binarization of grayscale images using the Otsu algorithm
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Finding external and internal contours in a binary image
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Extracting connected components from a binary image
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Fitting lines and circles into two-dimensional point sets
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Calculating image moments
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Working with curves - approximation, length, and area
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Checking whether a point is within a contour
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Computing distance maps
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Image segmentation using the k-means algorithm
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Image segmentation using segment seeds - the watershed algorithm
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Object Detection and Machine Learning
    1. Introduction
    2. Obtaining an object mask using the GrabCut algorithm
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Finding edges using the Canny algorithm
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Detecting lines and circles using the Hough transform
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Finding objects via template matching
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. The medial flow tracker
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Tracking objects using different algorithms via the tracking API
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Computing the dense optical flow between two frames
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Detecting chessboard and circle grid patterns
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. A simple pedestrian detector using the SVM model
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Optical character recognition using different machine learning models
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Detecting faces using Haar/LBP cascades
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Detecting AruCo patterns for AR applications
      1. Getting ready
      2. How to do it...
      3. How it works...
    14. Detecting text in natural scenes
      1. Getting ready
      2. How to do it...
      3. How it works...
    15. QR code detector
      1. Getting ready
      2. How to do it...
      3. How it works...
  10. Deep Learning
    1. Introduction
    2. Representing images as tensors/blobs
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Loading deep learning models from Caffe, Torch, and TensorFlow formats
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Getting input and output tensors' shapes for all layers
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Preprocessing images and inference in convolutional networks
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Measuring inference time and contributions to it from each layer
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Classifying images with GoogleNet/Inception and ResNet models
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Detecting objects with the Single Shot Detection (SSD) model
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Segmenting a scene using the Fully Convolutional Network (FCN) model
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Face detection using Single Shot Detection (SSD) and the ResNet model
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Age and gender prediction
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Linear Algebra
    1. Introduction
    2. The orthogonal Procrustes problem
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Rank-constrained matrix approximation
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Principal component analysis
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Solving systems of linear equations (including under- and over-determined)
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Solving polynomial equations
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Linear programming with the simplex method
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Detectors and Descriptors
    1. Introduction
    2. Finding corners in an image - Harris and FAST
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Selecting good corners in an image for tracking
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Drawing keypoints, descriptors, and matches
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Detecting scale invariant keypoints
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Computing descriptors for image keypoints - SURF, BRIEF, ORB
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Matching techniques for finding correspondences between descriptors
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Finding reliable matches - cross-check and ratio test
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Model-based filtering of matches - RANSAC
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. BoW model for constructing global image descriptors
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Image and Video Processing
    1. Introduction
    2. Warping an image using affine and perspective transformations
      1. Getting ready
      2. How to do it
      3. How it works
    3. Remapping an image using arbitrary transformation
      1. Getting ready
      2. How to do it
      3. How it works
    4. Tracking keypoints between frames using the Lucas-Kanade algorithm
      1. Getting ready
      2. How to do it
      3. How it works
    5. Background subtraction
      1. Getting ready
      2. How to do it
      3. How it works
    6. Stitching many images into panorama
      1. Getting ready
      2. How to do it
      3. How it works
    7. Denoising a photo using non-local means algorithms
      1. Getting ready
      2. How to do it
      3. How it works
    8. Constructing an HDR image
      1. Getting ready
      2. How to do it
      3. How it works
    9. Removing defects from a photo with image inpainting
      1. Getting ready
      2. How to do it
      3. How it works
  14. Multiple View Geometry
    1. Introduction
    2. Pinhole camera model calibration
      1. Getting ready
      2. How to do it
      3. How it works
    3. Fisheye camera model calibration
      1. Getting ready
      2. How to do it
      3. How it works
    4. Stereo rig calibration - estimation of extrinsics
      1. Getting ready
      2. How to do it
      3. How it works
    5. Distorting and undistorting points
      1. Getting ready
      2. How to do it
      3. How it works
    6. Removing lens distortion effects from an image
      1. Getting ready
      2. How to do it
      3. How it works
    7. Restoring a 3D point from two observations through triangulation
      1. Getting ready
      2. How to do it
      3. How it works
    8. Finding a relative camera-object pose through the PnP algorithm
      1. Getting ready
      2. How to do it
      3. How it works
    9. Aligning two views through stereo rectification
      1. Getting ready
      2. How to do it
      3. How it works
    10. Epipolar geometry - computing fundamental and essential matrices
      1. Getting ready
      2. How to do it
      3. How it works
    11. Essential matrix decomposition into rotation and translation
      1. Getting ready
      2. How to do it
      3. How it works
    12. Estimating disparity maps for stereo images
      1. Getting ready
      2. How to do it
      3. How it works
    13. Special case 2-view geometry - estimating homography transformation
      1. Getting ready
      2. How to do it
      3. How it works
    14. Planar scene - decomposing homography into rotation and translation
      1. Getting ready
      2. How to do it
      3. How it works
    15. Rotational camera case - estimating camera rotation from homography
      1. Getting ready
      2. How to do it
      3. How it works
  15. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think