Book Image

OpenCV 4 for Secret Agents - Second Edition

By : Joseph Howse
Book Image

OpenCV 4 for Secret Agents - Second Edition

By: Joseph Howse

Overview of this book

OpenCV 4 is a collection of image processing functions and computer vision algorithms. It is open source, supports many programming languages and platforms, and is fast enough for many real-time applications. With this handy library, you’ll be able to build a variety of impressive gadgets. OpenCV 4 for Secret Agents features a broad selection of projects based on computer vision, machine learning, and several application frameworks. To enable you to build apps for diverse desktop systems and Raspberry Pi, the book supports multiple Python versions, from 2.7 to 3.7. For Android app development, the book also supports Java in Android Studio, and C# in the Unity game engine. Taking inspiration from the world of James Bond, this book will add a touch of adventure and computer vision to your daily routine. You’ll be able to protect your home and car with intelligent camera systems that analyze obstacles, people, and even cats. In addition to this, you’ll also learn how to train a search engine to praise or criticize the images that it finds, and build a mobile app that speaks to you and responds to your body language. By the end of this book, you will be equipped with the knowledge you need to advance your skills as an app developer and a computer vision specialist.
Table of Contents (16 chapters)
Free Chapter
1
Section 1: The Briefing
4
Section 2: The Chase
9
Section 3: The Big Reveal
12
Making WxUtils.py Compatible with Raspberry Pi
13
Learning More about Feature Detection in OpenCV
14
Running with Snakes (or, First Steps with Python)

Understanding optical flow

Optical flow is the pattern of apparent motion between two consecutive frames of video. We select feature points in the first frame and try to determine where those features have gone in the second frame. This search is subject to a few caveats:

  • We make no attempt to distinguish between camera motion and subject motion.
  • We assume that a feature's color or brightness remains similar between frames.
  • We assume that neighboring pixels have similar motions.

OpenCV's calcOpticalFlowPyrLK function implements the Lucas-Kanade method of computing optical flow. Lucas-Kanade relies on a 3 x 3 neighborhood (that is, 9 pixels) around each feature. Taking each feature's neighborhood from the first frame, we try to find the best matching neighborhood in the second frame, based on least squares error. OpenCV's implementation of Lucas-Kanade uses...