You are previewing OpenCV for Secret Agents.
O'Reilly logo
OpenCV for Secret Agents

Book Description

Use OpenCV in six secret projects to augment your home, car, phone, eyesight, and any photo or drawing

In Detail

OpenCV is a grand collection of image processing functions and computer vision algorithms. It is open source, it supports many programming languages and platforms, and it is fast enough for many real-time applications. What a lot of gadgets we can build with such a handy library!

Taking inspiration from the world of James Bond, this book adds a spark of adventure and computer vision to your daily routine. Protect your home and car with intelligent camera systems that analyze people, cats, and obstacles. Let your search engine praise or criticize the images that it finds. Hear a voice from your phone that responds to your body language. Attune yourself to another person's rhythm by glancing at a display that magnifies a heartbeat or a breath. Learn OpenCV and see your world as never before.

What You Will Learn

  • Install OpenCV, a Python development environment, and an Android development environment on Windows, Mac, or Linux and install a Unity development environment on Windows or Mac

  • Get to grips with motion detection and gesture recognition as a means of controlling a guessing game on a smartphone

  • Detect car headlights, estimate distances to them, and provide feedback to the driver

  • Spot and recognize human faces and cat faces as a means of controlling an alarm

  • Amplify motion in real-time video so that a person's heartbeat and breathing become clearly visible

  • Draw a ball-in-a-maze puzzle on paper and see it come to life as a physics simulation on a smartphone

  • Integrate OpenCV with other libraries, as well as popular frameworks for GUI apps and games

  • 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. OpenCV for Secret Agents
      1. Table of Contents
      2. OpenCV for Secret Agents
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. 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
      9. 1. Preparing for the Mission
        1. Setting up a development machine
          1. Windows
            1. OpenCV on Windows with binary installers
            2. OpenCV on Windows with CMake and compilers
          2. Mac
            1. Mac with MacPorts
            2. Mac with Homebrew
          3. Debian Wheezy and its derivatives, including Raspbian, Ubuntu, and Linux Mint
          4. Fedora and its derivatives, including RHEL and CentOS
          5. openSUSE and its derivatives
          6. Tegra Android Development Pack
            1. Building OpenCV Android sample projects with Eclipse
          7. Unity
        2. Setting up Raspberry Pi
          1. Setting up the Raspberry Pi Camera Module
        3. Finding OpenCV documentation, help, and updates
        4. Alternatives to Raspberry Pi
        5. Summary
      10. 2. Searching for Luxury Accommodations Worldwide
        1. Planning the Luxocator app
        2. Creating, comparing, and storing histograms
        3. Training the classifier with reference images
        4. Acquiring images from the Web
        5. Acquiring images from Bing image search
        6. Preparing images and resources for the app
        7. Integrating everything into the GUI
        8. Building Luxocator for distribution
        9. Summary
      11. 3. Training a Smart Alarm to Recognize the Villain and His Cat
        1. Understanding machine learning in general
        2. Planning the Interactive Recognizer app
        3. Understanding Haar cascades and LBPH
        4. Implementing the Interactive Recognizer app
        5. Planning the cat detection model
        6. Implementing the training script for the cat detection model
        7. Planning the Angora Blue app
        8. Implementing the Angora Blue app
        9. Building Angora Blue for distribution
        10. Further fun with finding felines
        11. Summary
      12. 4. Controlling a Phone App with Your Suave Gestures
        1. Planning the Goldgesture app
        2. Understanding optical flow
        3. Setting up the Eclipse Workspace
        4. Getting a cascade file and audio files
        5. Specifying the app's requirements
        6. Laying out a camera preview as the main view
        7. Tracking back and forth gestures
        8. Playing audio clips as questions and answers
        9. Capturing images and tracking faces in an activity
        10. Summary
      13. 5. Equipping Your Car with a Rearview Camera and Hazard Detection
        1. Planning The Living Headlights app
        2. Detecting lights as blobs
        3. Estimating distances (a cheap approach)
        4. Implementing The Living Headlights app
        5. Testing The Living Headlights app at home
        6. Testing The Living Headlights app in a car
        7. Summary
      14. 6. Seeing a Heartbeat with a Motion Amplifying Camera
        1. Planning the Lazy Eyes app
        2. Understanding what Eulerian video magnification can do
        3. Extracting repeating signals from video using the Fast Fourier Transform (FFT)
          1. Choosing and setting up an FFT library
        4. Compositing two images using image pyramids
        5. Implementing the Lazy Eyes app
        6. Configuring and testing the app for various motions
        7. Seeing things in another light
        8. Summary
      15. 7. Creating a Physics Simulation Based on a Pen and Paper Sketch
        1. Planning the Rollingball app
        2. Detecting circles and lines
        3. Setting up OpenCV for Unity
        4. Configuring and building the Unity project
        5. Creating the Rollingball scene in Unity
        6. Creating Unity assets and adding them to the scene
          1. Writing shaders and creating materials
          2. Creating physics materials
          3. Creating prefabs
          4. Writing our first Unity script
          5. Writing the main Rollingball script
        7. Tidying up and testing
        8. Summary
      16. Index