logo资料库

Learning Opencv3(英文原版).pdf

第1页 / 共1018页
第2页 / 共1018页
第3页 / 共1018页
第4页 / 共1018页
第5页 / 共1018页
第6页 / 共1018页
第7页 / 共1018页
第8页 / 共1018页
资料共1018页,剩余部分请下载后查看
Copyright
Table of Contents
Preface
Purpose of This Book
Who This Book Is For
What This Book Is Not
About the Programs in This Book
Prerequisites
How This Book Is Best Used
Conventions Used in This Book
Using Code Examples
O’Reilly Safari
We’d Like to Hear from You
Acknowledgments
Thanks for Help on OpenCV
Thanks for Help on This Book
Adrian Adds...
Gary Adds...
Chapter 1. Overview
What Is OpenCV?
Who Uses OpenCV?
What Is Computer Vision?
The Origin of OpenCV
OpenCV Block Diagram
Speeding Up OpenCV with IPP
Who Owns OpenCV?
Downloading and Installing OpenCV
Installation
Getting the Latest OpenCV via Git
More OpenCV Documentation
Supplied Documentation
Online Documentation and the Wiki
OpenCV Contribution Repository
Downloading and Building Contributed Modules
Portability
Summary
Exercises
Chapter 2. Introduction to OpenCV
Include Files
Resources
First Program—Display a Picture
Second Program—Video
Moving Around
A Simple Transformation
A Not-So-Simple Transformation
Input from a Camera
Writing to an AVI File
Summary
Exercises
Chapter 3. Getting to Know OpenCV Data Types
The Basics
OpenCV Data Types
Overview of the Basic Types
Basic Types: Getting Down to Details
Helper Objects
Utility Functions
The Template Structures
Summary
Exercises
Chapter 4. Images and Large Array Types
Dynamic and Variable Storage
The cv::Mat Class: N-Dimensional Dense Arrays
Creating an Array
Accessing Array Elements Individually
The N-ary Array Iterator: NAryMatIterator
Accessing Array Elements by Block
Matrix Expressions: Algebra and cv::Mat
Saturation Casting
More Things an Array Can Do
The cv::SparseMat Class: Sparse Arrays
Accessing Sparse Array Elements
Functions Unique to Sparse Arrays
Template Structures for Large Array Types
Summary
Exercises
Chapter 5. Array Operations
More Things You Can Do with Arrays
cv::abs()
cv::absdiff()
cv::add()
cv::addWeighted()
cv::bitwise_and()
cv::bitwise_not()
cv::bitwise_or()
cv::bitwise_xor()
cv::calcCovarMatrix()
cv::cartToPolar()
cv::checkRange()
cv::compare()
cv::completeSymm()
cv::convertScaleAbs()
cv::countNonZero()
cv::cvarrToMat()
cv::dct()
cv::dft()
cv::cvtColor()
cv::determinant()
cv::divide()
cv::eigen()
cv::exp()
cv::extractImageCOI()
cv::flip()
cv::gemm()
cv::getConvertElem() and cv::getConvertScaleElem()
cv::idct()
cv::idft()
cv::inRange()
cv::insertImageCOI()
cv::invert()
cv::log()
cv::LUT()
cv::magnitude()
cv::Mahalanobis()
cv::max()
cv::mean()
cv::meanStdDev()
cv::merge()
cv::min()
cv::minMaxIdx()
cv::minMaxLoc()
cv::mixChannels()
cv::mulSpectrums()
cv::multiply()
cv::mulTransposed()
cv::norm()
cv::normalize()
cv::perspectiveTransform()
cv::phase()
cv::polarToCart()
cv::pow()
cv::randu()
cv::randn()
cv::randShuffle()
cv::reduce()
cv::repeat()
cv::scaleAdd()
cv::setIdentity()
cv::solve()
cv::solveCubic()
cv::solvePoly()
cv::sort()
cv::sortIdx()
cv::split()
cv::sqrt()
cv::subtract()
cv::sum()
cv::trace()
cv::transform()
cv::transpose()
Summary
Exercises
Chapter 6. Drawing and Annotating
Drawing Things
Line Art and Filled Polygons
Fonts and Text
Summary
Exercises
Chapter 7. Functors in OpenCV
Objects That “Do Stuff”
Principal Component Analysis (cv::PCA)
Singular Value Decomposition (cv::SVD)
Random Number Generator (cv::RNG)
Summary
Exercises
Chapter 8. Image, Video, and Data Files
HighGUI: Portable Graphics Toolkit
Working with Image Files
Loading and Saving Images
A Note About Codecs
Compression and Decompression
Working with Video
Reading Video with the cv::VideoCapture Object
Writing Video with the cv::VideoWriter Object
Data Persistence
Writing to a cv::FileStorage
Reading from a cv::FileStorage
cv::FileNode
Summary
Exercises
Chapter 9. Cross-Platform and Native Windows
Working with Windows
HighGUI Native Graphical User Interface
Working with the Qt Backend
Integrating OpenCV with Full GUI Toolkits
Summary
Exercises
Chapter 10. Filters and Convolution
Overview
Before We Begin
Filters, Kernels, and Convolution
Border Extrapolation and Boundary Conditions
Threshold Operations
Otsu’s Algorithm
Adaptive Threshold
Smoothing
Simple Blur and the Box Filter
Median Filter
Gaussian Filter
Bilateral Filter
Derivatives and Gradients
The Sobel Derivative
Scharr Filter
The Laplacian
Image Morphology
Dilation and Erosion
The General Morphology Function
Opening and Closing
Morphological Gradient
Top Hat and Black Hat
Making Your Own Kernel
Convolution with an Arbitrary Linear Filter
Applying a General Filter with cv::filter2D()
Applying a General Separable Filter with cv::sepFilter2D
Kernel Builders
Summary
Exercises
Chapter 11. General Image Transforms
Overview
Stretch, Shrink, Warp, and Rotate
Uniform Resize
Image Pyramids
Nonuniform Mappings
Affine Transformation
Perspective Transformation
General Remappings
Polar Mappings
LogPolar
Arbitrary Mappings
Image Repair
Inpainting
Denoising
Histogram Equalization
cv::equalizeHist(): Contrast equalization
Summary
Exercises
Chapter 12. Image Analysis
Overview
Discrete Fourier Transform
cv::dft(): The Discrete Fourier Transform
cv::idft(): The Inverse Discrete Fourier Transform
cv::mulSpectrums(): Spectrum Multiplication
Convolution Using Discrete Fourier Transforms
cv::dct(): The Discrete Cosine Transform
cv::idct(): The Inverse Discrete Cosine Transform
Integral Images
cv::integral() for Standard Summation Integral
cv::integral() for Squared Summation Integral
cv::integral() for Tilted Summation Integral
The Canny Edge Detector
cv::Canny()
Hough Transforms
Hough Line Transform
Hough Circle Transform
Distance Transformation
cv::distanceTransform() for Unlabeled Distance Transform
cv::distanceTransform() for Labeled Distance Transform
Segmentation
Flood Fill
Watershed Algorithm
Grabcuts
Mean-Shift Segmentation
Summary
Exercises
Chapter 13. Histograms and Templates
Histogram Representation in OpenCV
cv::calcHist(): Creating a Histogram from Data
Basic Manipulations with Histograms
Histogram Normalization
Histogram Threshold
Finding the Most Populated Bin
Comparing Two Histograms
Histogram Usage Examples
Some More Sophisticated Histograms Methods
Earth Mover’s Distance
Back Projection
Template Matching
Square Difference Matching Method (cv::TM_SQDIFF)
Normalized Square Difference Matching Method (cv::TM_SQDIFF_NORMED)
Correlation Matching Methods (cv::TM_CCORR)
Normalized Cross-Correlation Matching Method (cv::TM_CCORR_NORMED)
Correlation Coefficient Matching Methods (cv::TM_CCOEFF)
Normalized Correlation Coefficient Matching Method (cv::TM_CCOEFF_NORMED)
Summary
Exercises
Chapter 14. Contours
Contour Finding
Contour Hierarchies
Drawing Contours
A Contour Example
Another Contour Example
Fast Connected Component Analysis
More to Do with Contours
Polygon Approximations
Geometry and Summary Characteristics
Geometrical Tests
Matching Contours and Images
Moments
More About Moments
Matching and Hu Moments
Using Shape Context to Compare Shapes
Summary
Exercises
Chapter 15. Background Subtraction
Overview of Background Subtraction
Weaknesses of Background Subtraction
Scene Modeling
A Slice of Pixels
Frame Differencing
Averaging Background Method
Accumulating Means, Variances, and Covariances
A More Advanced Background Subtraction Method
Structures
Learning the Background
Learning with Moving Foreground Objects
Background Differencing: Finding Foreground Objects
Using the Codebook Background Model
A Few More Thoughts on Codebook Models
Connected Components for Foreground Cleanup
A Quick Test
Comparing Two Background Methods
OpenCV Background Subtraction Encapsulation
The cv::BackgroundSubtractor Base Class
KaewTraKuPong and Bowden Method
Zivkovic Method
Summary
Exercises
Chapter 16. Keypoints and Descriptors
Keypoints and the Basics of Tracking
Corner Finding
Introduction to Optical Flow
Lucas-Kanade Method for Sparse Optical Flow
Generalized Keypoints and Descriptors
Optical Flow, Tracking, and Recognition
How OpenCV Handles Keypoints and Descriptors, the General Case
Core Keypoint Detection Methods
Keypoint Filtering
Matching Methods
Displaying Results
Summary
Exercises
Chapter 17. Tracking
Concepts in Tracking
Dense Optical Flow
The Farnebäck Polynomial Expansion Algorithm
The Dual TV-L1 Algorithm
The Simple Flow Algorithm
Mean-Shift and Camshift Tracking
Mean-Shift
Camshift
Motion Templates
Estimators
The Kalman Filter
A Brief Note on the Extended Kalman Filter
Summary
Exercises
Chapter 18. Camera Models and Calibration
Camera Model
The Basics of Projective Geometry
Rodrigues Transform
Lens Distortions
Calibration
Rotation Matrix and Translation Vector
Calibration Boards
Homography
Camera Calibration
Undistortion
Undistortion Maps
Converting Undistortion Maps Between Representations with cv::convertMaps()
Computing Undistortion Maps with cv::initUndistortRectifyMap()
Undistorting an Image with cv::remap()
Undistortion with cv::undistort()
Sparse Undistortion with cv::undistortPoints()
Putting Calibration All Together
Summary
Exercises
Chapter 19. Projection and Three-Dimensional Vision
Projections
Affine and Perspective Transformations
Bird’s-Eye-View Transform Example
Three-Dimensional Pose Estimation
Pose Estimation from a Single Camera
Stereo Imaging
Triangulation
Epipolar Geometry
The Essential and Fundamental Matrices
Computing Epipolar Lines
Stereo Calibration
Stereo Rectification
Stereo Correspondence
Stereo Calibration, Rectification, and Correspondence Code Example
Depth Maps from Three-Dimensional Reprojection
Structure from Motion
Fitting Lines in Two and Three Dimensions
Summary
Exercises
Chapter 20. The Basics of Machine Learning in OpenCV
What Is Machine Learning?
Training and Test Sets
Supervised and Unsupervised Learning
Generative and Discriminative Models
OpenCV ML Algorithms
Using Machine Learning in Vision
Variable Importance
Diagnosing Machine Learning Problems
Legacy Routines in the ML Library
K-Means
Mahalanobis Distance
Summary
Exercises
Chapter 21. StatModel: The Standard Model for Learning in OpenCV
Common Routines in the ML Library
Training and the cv::ml::TrainData Structure
Prediction
Machine Learning Algorithms Using cv::StatModel
Naïve/Normal Bayes Classifier
Binary Decision Trees
Boosting
Random Trees
Expectation Maximization
K-Nearest Neighbors
Multilayer Perceptron
Support Vector Machine
Summary
Exercises
Chapter 22. Object Detection
Tree-Based Object Detection Techniques
Cascade Classifiers
Supervised Learning and Boosting Theory
Learning New Objects
Object Detection Using Support Vector Machines
Latent SVM for Object Detection
The Bag of Words Algorithm and Semantic Categorization
Summary
Exercises
Chapter 23. Future of OpenCV
Past and Present
OpenCV 3.x
How Well Did Our Predictions Go Last Time?
Future Functions
Current GSoC Work
Community Contributions
OpenCV.org
Some AI Speculation
Afterword
Appendix A. Planar Subdivisions
Delaunay Triangulation, Voronoi Tesselation
Creating a Delaunay or Voronoi Subdivision
Navigating Delaunay Subdivisions
Usage Examples
Exercises
Appendix B. opencv_contrib
An Overview of the opencv_contrib Modules
Contents of opencv_contrib
Appendix C. Calibration Patterns
Calibration Patterns Used by OpenCV
Bibliography
Index
About the Authors
Colophon
Learning OpenCV 3 COMPUTER VISION IN C++ WITH THE OPENCV LIBRARY Adrian Kaehler & Gary Bradski
Learning OpenCV 3 Computer Vision in C++ with the OpenCV Library Adrian Kaehler and Gary Bradski Beijing Beijing Boston Boston Farnham Sebastopol Farnham Sebastopol Tokyo Tokyo
Learning OpenCV 3 by Adrian Kaehler and Gary Bradski Copyright © 2017 Adrian Kaehler, Gary Bradski. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://www.oreilly.com/safari). For more information, contact our corpo‐ rate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Indexer: Ellen Troutman Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest Editor: Dawn Schanafelt Production Editor: Kristen Brown Copyeditor: Rachel Monaghan Proofreader: James Fraleigh December 2016: First Edition Revision History for the First Edition 2016-12-09: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781491937990 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning OpenCV 3, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-491-93799-0 [M]
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv 1. Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What Is OpenCV? 1 Who Uses OpenCV? 2 What Is Computer Vision? 3 The Origin of OpenCV 6 OpenCV Block Diagram 8 Speeding Up OpenCV with IPP 9 Who Owns OpenCV? 10 Downloading and Installing OpenCV 10 Installation 10 Getting the Latest OpenCV via Git 13 More OpenCV Documentation 13 Supplied Documentation 14 Online Documentation and the Wiki 14 OpenCV Contribution Repository 17 Downloading and Building Contributed Modules 17 Portability 18 Summary 19 Exercises 19 2. Introduction to OpenCV. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Include Files 21 Resources 22 First Program—Display a Picture 23 Second Program—Video 25 Moving Around 27 iii
A Simple Transformation 31 A Not-So-Simple Transformation 32 Input from a Camera 35 Writing to an AVI File 36 Summary 38 Exercises 38 3. Getting to Know OpenCV Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 The Basics 41 OpenCV Data Types 41 Overview of the Basic Types 42 Basic Types: Getting Down to Details 44 Helper Objects 52 Utility Functions 60 The Template Structures 67 Summary 68 Exercises 69 4. Images and Large Array Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Dynamic and Variable Storage 71 The cv::Mat Class: N-Dimensional Dense Arrays 72 Creating an Array 73 Accessing Array Elements Individually 78 The N-ary Array Iterator: NAryMatIterator 81 Accessing Array Elements by Block 84 Matrix Expressions: Algebra and cv::Mat 85 Saturation Casting 87 More Things an Array Can Do 88 The cv::SparseMat Class: Sparse Arrays 89 Accessing Sparse Array Elements 90 Functions Unique to Sparse Arrays 92 Template Structures for Large Array Types 94 Summary 97 Exercises 97 5. Array Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 More Things You Can Do with Arrays 99 cv::abs() 102 cv::absdiff() 103 cv::add() 103 cv::addWeighted() 104 cv::bitwise_and() 106 iv | Table of Contents
cv::bitwise_not() 107 cv::bitwise_or() 107 cv::bitwise_xor() 108 cv::calcCovarMatrix() 108 cv::cartToPolar() 110 cv::checkRange() 111 cv::compare() 111 cv::completeSymm() 112 cv::convertScaleAbs() 112 cv::countNonZero() 113 cv::cvarrToMat() 113 cv::dct() 114 cv::dft() 115 cv::cvtColor() 117 cv::determinant() 119 cv::divide() 120 cv::eigen() 120 cv::exp() 121 cv::extractImageCOI() 121 cv::flip() 122 cv::gemm() 122 cv::getConvertElem() and cv::getConvertScaleElem() 123 cv::idct() 124 cv::idft() 124 cv::inRange() 124 cv::insertImageCOI() 125 cv::invert() 126 cv::log() 126 cv::LUT() 127 cv::magnitude() 127 cv::Mahalanobis() 128 cv::max() 129 cv::mean() 130 cv::meanStdDev() 130 cv::merge() 131 cv::min() 131 cv::minMaxIdx() 132 cv::minMaxLoc() 133 cv::mixChannels() 134 cv::mulSpectrums() 136 cv::multiply() 136 cv::mulTransposed() 136 Table of Contents | v
cv::norm() 137 cv::normalize() 139 cv::perspectiveTransform() 140 cv::phase() 141 cv::polarToCart() 142 cv::pow() 142 cv::randu() 143 cv::randn() 143 cv::randShuffle() 144 cv::reduce() 144 cv::repeat() 145 cv::scaleAdd() 146 cv::setIdentity() 146 cv::solve() 147 cv::solveCubic() 148 cv::solvePoly() 149 cv::sort() 149 cv::sortIdx() 149 cv::split() 150 cv::sqrt() 150 cv::subtract() 152 cv::sum() 152 cv::trace() 152 cv::transform() 153 cv::transpose() 153 Summary 154 Exercises 154 6. Drawing and Annotating. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Drawing Things 157 Line Art and Filled Polygons 158 Fonts and Text 165 Summary 167 Exercises 167 7. Functors in OpenCV. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Objects That “Do Stuff” 169 Principal Component Analysis (cv::PCA) 169 Singular Value Decomposition (cv::SVD) 173 Random Number Generator (cv::RNG) 176 Summary 179 Exercises 180 vi | Table of Contents
分享到:
收藏