OpenCV with Python By Example
Table of Contents
OpenCV with Python By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Applying Geometric Transformations to Images
Installing OpenCV-Python
Windows
Mac OS X
Linux (for Ubuntu)
Reading, displaying, and saving images
What just happened?
Loading and saving an image
Image color spaces
Converting between color spaces
What just happened?
Image translation
What just happened?
Image rotation
What just happened?
Image scaling
What just happened?
Affine transformations
What just happened?
Projective transformations
What just happened?
Image warping
Summary
2. Detecting Edges and Applying Image Filters
2D convolution
Blurring
The size of the kernel versus the blurriness
Edge detection
Motion blur
Under the hood
Sharpening
Understanding the pattern
Embossing
Erosion and dilation
Afterthought
Creating a vignette filter
What's happening underneath?
How do we move the focus around?
Enhancing the contrast in an image
How do we handle color images?
Summary
3. Cartoonizing an Image
Accessing the webcam
Under the hood
Keyboard inputs
Interacting with the application
Mouse inputs
What's happening underneath?
Interacting with a live video stream
How did we do it?
Cartoonizing an image
Deconstructing the code
Summary
4. Detecting and Tracking Different Body Parts
Using Haar cascades to detect things
What are integral images?
Detecting and tracking faces
Understanding it better
Fun with faces
Under the hood
Detecting eyes
Afterthought
Fun with eyes
Positioning the sunglasses
Detecting ears
Detecting a mouth
It's time for a moustache
Detecting a nose
Detecting pupils
Deconstructing the code
Summary
5. Extracting Features from an Image
Why do we care about keypoints?
What are keypoints?
Detecting the corners
Good Features To Track
Scale Invariant Feature Transform (SIFT)
Speeded Up Robust Features (SURF)
Features from Accelerated Segment Test (FAST)
Binary Robust Independent Elementary Features (BRIEF)
Oriented FAST and Rotated BRIEF (ORB)
Summary
6. Creating a Panoramic Image
Matching keypoint descriptors
How did we match the keypoints?
Understanding the matcher object
Drawing the matching keypoints
Creating the panoramic image
Finding the overlapping regions
Stitching the images
What if the images are at an angle to each other?
Why does it look stretched?
Summary
7. Seam Carving
Why do we care about seam carving?
How does it work?
How do we define "interesting"?
How do we compute the seams?
Can we expand an image?
Can we remove an object completely?
How did we do it?
Summary
8. Detecting Shapes and Segmenting an Image
Contour analysis and shape matching
Approximating a contour
Identifying the pizza with the slice taken out
How to censor a shape?
What is image segmentation?
How does it work?
Watershed algorithm
Summary
9. Object Tracking
Frame differencing
Colorspace based tracking
Building an interactive object tracker
Feature based tracking
Background subtraction
Summary
10. Object Recognition
Object detection versus object recognition
What is a dense feature detector?
What is a visual dictionary?
What is supervised and unsupervised learning?
What are Support Vector Machines?
What if we cannot separate the data with simple straight lines?
How do we actually implement this?
What happened inside the code?
How did we build the trainer?
Summary
11. Stereo Vision and 3D Reconstruction
What is stereo correspondence?
What is epipolar geometry?
Why are the lines different as compared to SIFT?
Building the 3D map
Summary
12. Augmented Reality
What is the premise of augmented reality?
What does an augmented reality system look like?
Geometric transformations for augmented reality
What is pose estimation?
How to track planar objects?
What happened inside the code?
How to augment our reality?
Mapping coordinates from 3D to 2D
How to overlay 3D objects on a video?
Let's look at the code
Let's add some movements
Summary
Index
OpenCV with Python By Example
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: September 2015
Production reference: 1150915
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-393-2
www.packtpub.com
Author
Prateek Joshi
Reviewers
Will Brennan
Gabriel Garrido Calvo
Pavan Kumar Pavagada Nagaraja
Marvin Smith
Commissioning Editor
Deepika Gaonkar
Acquisition Editor
Tushar Gupta
Content Development Editor
Sumeet Sawant
Technical Editor
Ryan Kochery
Copy Editors
Merilyn Pereira
Angad Singh
Project Coordinator
Shweta H Birwatkar
Proofreader
Safis Editing
Indexer
Tejal Daruwale Soni
Graphics
Jason Monteiro
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
Prateek Joshi is a computer vision researcher with a primary focus on content-based analysis. He is particularly interested in intelligent algorithms that can understand images to produce scene descriptions in terms of constituent objects. He has a master's degree from the University of Southern California, specializing in computer vision. He was elected to become a member of the Honor Society for academic excellence and an ambassador for the School of Engineering. Over the course of his career, he has worked for companies such as Nvidia, Microsoft Research, Qualcomm, and a couple of early stage start-ups in Silicon Valley.
His work in this field has resulted in multiple patents, tech demos, and research papers at major IEEE conferences. He has won many hackathons using a wide variety of technologies related to image recognition. He enjoys blogging about topics such as artificial intelligence, abstract mathematics, and cryptography. His blog has been visited by users in more than 200 countries, and he ...