logo资料库

Mastering OpenCV with Practical Computer Vision Projects .pdf

第1页 / 共340页
第2页 / 共340页
第3页 / 共340页
第4页 / 共340页
第5页 / 共340页
第6页 / 共340页
第7页 / 共340页
第8页 / 共340页
资料共340页,剩余部分请下载后查看
Cover
Copyright
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Cartoonifier and Skin Changer for Android
Accessing the webcam
Main camera processing loop for a desktop app
Generating a black-and-white sketch
Generating a color painting and a cartoon
Generating an "evil" mode using edge filters
Generating an "alien" mode using skin detection
Skin-detection algorithm
Showing the user where to put their face
Implementation of the skin-color changer
Porting from desktop to Android
Setting up an Android project that uses OpenCV
Color formats used for image processing on Android
Input color format from the camera
Output color format for display
Adding the cartoonifier code to the Android NDK app
Reviewing the Android app
Cartoonifying the image when the user taps the screen
Saving the image to a file and to the Android picture gallery
Showing an Android notification message about a saved image
Changing cartoon modes through the Android menu bar
Reducing the random pepper noise from the sketch image
Showing the FPS of the app
Using a different camera resolution
Customizing the app
Summary
Chapter 2: Marker-based Augmented Reality on iPhone or iPad
Creating an iOS project that uses OpenCV
Adding OpenCV framework
Including OpenCV headers
Application architecture
Marker detection
Marker identification
Grayscale conversion
Image binarization
Contours detection
Candidates search
Marker code recognition
Reading marker code
Marker location refinement
Placing a marker in 3D
Camera calibration
Marker pose estimation
Rendering the 3D virtual object
Creating the OpenGL rendering layer
Rendering an AR scene
Summary
References
Chapter 3: Marker-less Augmented Reality
Marker-based versus marker-less AR
Using feature descriptors to find an arbitrary image on video
Feature extraction
Definition of a pattern object
Matching of feature points
PatternDetector.cpp
Outlier removal
Cross-match filter
Ratio test
Homography estimation
Homography refinement
Putting it all together
Pattern pose estimation
PatternDetector.cpp
Obtaining the camera-intrinsic matrix
Pattern.cpp
Application infrastructure
ARPipeline.hpp
ARPipeline.cpp
Enabling support for 3D visualization in OpenCV
Creating OpenGL windows using OpenCV
Video capture using OpenCV
Rendering augmented reality
ARDrawingContext.hpp
ARDrawingContext.cpp
Demonstration
main.cpp
Summary
References
Chapter 4: Exploring Structure from Motion Using OpenCV
Structure from Motion concepts
Estimating the camera motion from a pair of images
Point matching using rich feature descriptors
Point matching using optical flow
Finding camera matrices
Reconstructing the scene
Reconstruction from many views
Refinement of the reconstruction
Visualizing 3D point clouds with PCL
Using the example code
Summary
References
Chapter 5: Number Plate Recognition Using SVM and Neural Networks
Introduction to ANPR
ANPR algorithm
Plate detection
Segmentation
Classification
Plate recognition
OCR segmentation
Feature extraction
OCR classification
Evaluation
Summary
Chapter 6: Non-rigid Face Tracking
Overview
Utilities
Object-oriented design
Data collection: Image and video annotation
Training data types
Annotation tool
Pre-annotated data (The MUCT dataset)
Geometrical constraints
Procrustes analysis
Linear shape models
A combined local-global representation
Training and visualization
Facial feature-detectors
Correlation-based patch models
Learning discriminative patch models
Generative versus discriminative patch models
Accounting for global geometric transformations
Training and visualization
Face detection and initialization
Face tracking
Face tracker implementation
Training and visualization
Generic versus person-specific models
Summary
References
Chapter 7: 3D Head Pose Estimation Using AAM and POSIT
Active Appearance Models overview
Active Shape Models
Getting the feel of PCA
Triangulation
Triangle texture warping
Model Instantiation – playing with the Active Appearance Model
AAM search and fitting
POSIT
Diving into POSIT
POSIT and head model
Tracking from webcam or video file
Summary
References
Chapter 8: Face Recognition using Eigenfaces or Fisherfaces
Introduction to face recognition and face detection
Step 1: Face detection
Implementing face detection using OpenCV
Loading a Haar or LBP detector for object or face detection
Accessing the webcam
Detecting an object using the Haar or LBP Classifier
Detecting the face
Step 2: Face preprocessing
Eye detection
Eye search regions
Step 3: Collecting faces and learning from them
Collecting preprocessed faces for training
Training the face recognition system from collected faces
Viewing the learned knowledge
Average face
Eigenvalues, Eigenfaces, and Fisherfaces
Step 4: Face recognition
Face identification: Recognizing people from their face
Face verification: Validating that it is the claimed person
Finishing touches: Saving and loading files
Finishing touches: Making a nice and interactive GUI
Drawing the GUI elements
Checking and handling mouse clicks
Summary
References
Index
Mastering OpenCV with Practical Computer Vision Projects Step-by-step tutorials to solve common real-world computer vision problems for desktop or mobile, from augmented reality and number plate recognition to face recognition and 3D head tracking Daniel Lélis Baggio Shervin Emami David Millán Escrivá Khvedchenia Ievgen Naureen Mahmood Jason Saragih Roy Shilkrot BIRMINGHAM - MUMBAI
Mastering OpenCV with Practical Computer Vision Projects Copyright © 2012 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 authors, 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: December 2012 Production Reference: 2231112 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-782-9 www.packtpub.com Cover Image by Neha Rajappan (neha.rajappan1@gmail.com)
Credits Authors Daniel Lélis Baggio Shervin Emami David Millán Escrivá Khvedchenia Ievgen Naureen Mahmood Jason Saragih Roy Shilkrot Reviewers Kirill Kornyakov Luis Díaz Más Sebastian Montabone Acquisition Editor Usha Iyer Lead Technical Editor Ankita Shashi Technical Editors Sharvari Baet Prashant Salvi Copy Editors Brandt D'Mello Aditya Nair Alfida Paiva Project Coordinator Priya Sharma Proofreaders Chris Brown Martin Diver Indexer Hemangini Bari Tejal Soni Rekha Nair Graphics Valentina D'silva Aditi Gajjar Production Coordinator Arvindkumar Gupta Cover Work Arvindkumar Gupta
About the Authors Daniel Lélis Baggio started his work in computer vision through medical image processing at InCor (Instituto do Coração – Heart Institute) in São Paulo, where he worked with intra-vascular ultrasound image segmentation. Since then, he has focused on GPGPU and ported the segmentation algorithm to work with NVIDIA's CUDA. He has also dived into six degrees of freedom head tracking with a natural user interface group through a project called ehci (http://code.google.com/p/ ehci/). He now works for the Brazilian Air Force. I'd like to thank God for the opportunity of working with computer vision. I try to understand the wonderful algorithms He has created for us to see. I also thank my family, and especially my wife, for all their support throughout the development of the book. I'd like to dedicate this book to my son Stefano. Shervin Emami (born in Iran) taught himself electronics and hobby robotics during his early teens in Australia. While building his first robot at the age of 15, he learned how RAM and CPUs work. He was so amazed by the concept that he soon designed and built a whole Z80 motherboard to control his robot, and wrote all the software purely in binary machine code using two push buttons for 0s and 1s. After learning that computers can be programmed in much easier ways such as assembly language and even high-level compilers, Shervin became hooked to computer programming and has been programming desktops, robots, and smartphones nearly every day since then. During his late teens he created Draw3D (http://draw3d.shervinemami.info/), a 3D modeler with 30,000 lines of optimized C and assembly code that rendered 3D graphics faster than all the commercial alternatives of the time; but he lost interest in graphics programming when 3D hardware acceleration became available.
In University, Shervin took a subject on computer vision and became highly interested in it; so for his first thesis in 2003 he created a real-time face detection program based on Eigenfaces, using OpenCV (beta 3) for camera input. For his master's thesis in 2005 he created a visual navigation system for several mobile robots using OpenCV (v0.96). From 2008, he worked as a freelance Computer Vision Developer in Abu Dhabi and Philippines, using OpenCV for a large number of short-term commercial projects that included: • Detecting faces using Haar or Eigenfaces • Recognizing faces using Neural Networks, EHMM, or Eigenfaces • Detecting the 3D position and orientation of a face from a single photo using AAM and POSIT • Rotating a face in 3D using only a single photo • Face preprocessing and artificial lighting using any 3D direction from a single photo • Gender recognition • Facial expression recognition • Skin detection • Iris detection • Pupil detection • Eye-gaze tracking • Visual-saliency tracking • Histogram matching • Body-size detection • Shirt and bikini detection • Money recognition • Video stabilization • Face recognition on iPhone • Food recognition on iPhone • Marker-based augmented reality on iPhone (the second-fastest iPhone augmented reality app at the time).
OpenCV was putting food on the table for Shervin's family, so he began giving back to OpenCV through regular advice on the forums and by posting free OpenCV tutorials on his website (http://www.shervinemami.info/openCV.html). In 2011, he contacted the owners of other free OpenCV websites to write this book. He also began working on computer vision optimization for mobile devices at NVIDIA, working closely with the official OpenCV developers to produce an optimized version of OpenCV for Android. In 2012, he also joined the Khronos OpenVL committee for standardizing the hardware acceleration of computer vision for mobile devices, on which OpenCV will be based in the future. I thank my wife Gay and my baby Luna for enduring the stress while I juggled my time between this book, working fulltime, and raising a family. I also thank the developers of OpenCV, who worked hard for many years to provide a high-quality product for free. David Millán Escrivá was eight years old when he wrote his first program on an 8086 PC with Basic language, which enabled the 2D plotting of basic equations. In 2005, he finished his studies in IT through the Universitat Politécnica de Valencia with honors in human-computer interaction supported by computer vision with OpenCV (v0.96). He had a final project based on this subject and published it on HCI Spanish congress. He participated in Blender, an open source, 3D-software project, and worked in his first commercial movie Plumiferos - Aventuras voladoras as a Computer Graphics Software Developer. David now has more than 10 years of experience in IT, with experience in computer vision, computer graphics, and pattern recognition, working on different projects and startups, applying his knowledge of computer vision, optical character recognition, and augmented reality. He is the author of the "DamilesBlog" (http://blog.damiles.com), where he publishes research articles and tutorials about OpenCV, computer vision in general, and Optical Character Recognition algorithms.
David has reviewed the book gnuPlot Cookbook by Lee Phillips and published by Packt Publishing. Thanks Izaskun and my daughter Eider for their patience and support. Os quiero pequeñas. I also thank Shervin for giving me this opportunity, the OpenCV team for their work, the support of Artres, and the useful help provided by Augmate. Khvedchenia Ievgen is a computer vision expert from Ukraine. He started his career with research and development of a camera-based driver assistance system for Harman International. He then began working as a Computer Vision Consultant for ESG. Nowadays, he is a self-employed developer focusing on the development of augmented reality applications. Ievgen is the author of the Computer Vision Talks blog (http://computer-vision-talks.com), where he publishes research articles and tutorials pertaining to computer vision and augmented reality. I would like to say thanks to my father who inspired me to learn programming when I was 14. His help can't be overstated. And thanks to my mom, who always supported me in all my undertakings. You always gave me a freedom to choose my own way in this life. Thanks, parents! Thanks to Kate, a woman who totally changed my life and made it extremely full. I'm happy we're together. Love you.
分享到:
收藏