OpenCV Computer Vision Application Programming Cookbook Second Edition
()
About this ebook
Related to OpenCV Computer Vision Application Programming Cookbook Second Edition
Related ebooks
wxPython Application Development Cookbook Rating: 0 out of 5 stars0 ratingsOpenGL 4.0 Shading Language Cookbook Rating: 0 out of 5 stars0 ratingsOpenCV: Computer Vision Projects with Python Rating: 0 out of 5 stars0 ratingsLucene 4 Cookbook Rating: 0 out of 5 stars0 ratingsOpenGL Data Visualization Cookbook Rating: 0 out of 5 stars0 ratingsPython Data Visualization Cookbook Rating: 4 out of 5 stars4/5ActionScript Graphing Cookbook Rating: 0 out of 5 stars0 ratingsOpenCV 3 Computer Vision Application Programming Cookbook - Third Edition Rating: 0 out of 5 stars0 ratingsPython Parallel Programming Cookbook Rating: 5 out of 5 stars5/5matplotlib Plotting Cookbook Rating: 5 out of 5 stars5/5Lua Game Development Cookbook Rating: 0 out of 5 stars0 ratingsQt5 C++ GUI Programming Cookbook Rating: 0 out of 5 stars0 ratingsClojure Programming Cookbook Rating: 0 out of 5 stars0 ratingsMaya Programming with Python Cookbook Rating: 5 out of 5 stars5/5Learning OpenCV 3 Computer Vision with Python - Second Edition Rating: 0 out of 5 stars0 ratingsOpenCV with Python By Example Rating: 5 out of 5 stars5/5Mastering OpenCV 3 - Second Edition Rating: 0 out of 5 stars0 ratingsPython Multimedia Beginner's Guide Rating: 0 out of 5 stars0 ratingsBoost.Asio C++ Network Programming Cookbook Rating: 0 out of 5 stars0 ratingsSwift 2 Design Patterns Rating: 0 out of 5 stars0 ratingsOpenCV with Python Blueprints Rating: 5 out of 5 stars5/5Beginning JSON Rating: 0 out of 5 stars0 ratingsComputer Vision for the Web Rating: 0 out of 5 stars0 ratingsPractical Natural Language Processing with Python: With Case Studies from Industries Using Text Data at Scale Rating: 0 out of 5 stars0 ratingsOpenCV 3 Blueprints Rating: 0 out of 5 stars0 ratingsA Practical Approach for Machine Learning and Deep Learning Algorithms: Tools and Techniques Using MATLAB and Python Rating: 0 out of 5 stars0 ratingsPublishing Python Packages: Test, share, and automate your projects Rating: 0 out of 5 stars0 ratingsLearning Boost C++ Libraries Rating: 0 out of 5 stars0 ratingsAdvanced Graphics Programming Using OpenGL Rating: 2 out of 5 stars2/5Object-Oriented Graphics Programming in C++ Rating: 0 out of 5 stars0 ratings
Reviews for OpenCV Computer Vision Application Programming Cookbook Second Edition
0 ratings0 reviews
Book preview
OpenCV Computer Vision Application Programming Cookbook Second Edition - Robert Laganière
Table of Contents
OpenCV Computer Vision Application Programming Cookbook Second Edition
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
Errata
Piracy
Questions
1. Playing with Images
Introduction
Installing the OpenCV library
Getting ready
How to do it...
How it works...
There's more...
Using Qt for OpenCV developments
The OpenCV developer site
See also
Loading, displaying, and saving images
Getting ready
How to do it...
How it works...
There's more...
Clicking on images
Drawing on images
Running the example with Qt
See also
Exploring the cv::Mat data structure
How to do it...
How it works...
There's more...
The input and output arrays
The old IplImage structure
See also
Defining regions of interest
Getting ready
How to do it...
How it works...
There's more...
Using image masks
See also
2. Manipulating Pixels
Introduction
Accessing pixel values
Getting ready
How to do it...
How it works...
There's more...
The cv::Mat_ template class
See also
Scanning an image with pointers
Getting ready
How to do it...
How it works...
There's more...
Other color reduction formulas
Having input and output arguments
Efficient scanning of continuous images
Low-level pointer arithmetics
See also
Scanning an image with iterators
Getting ready
How to do it...
How it works...
There's more...
See also
Writing efficient image-scanning loops
How to do it...
How it works...
There's more…
See also
Scanning an image with neighbor access
Getting ready
How to do it...
How it works...
There's more...
See also
Performing simple image arithmetic
Getting ready
How to do it...
How it works...
There's more...
Overloaded image operators
Splitting the image channels
Remapping an image
How to do it...
How it works...
See also
3. Processing Color Images with Classes
Introduction
Using the Strategy pattern in an algorithm design
Getting ready
How to do it…
How it works…
There's more…
Computing the distance between two color vectors
Using OpenCV functions
The functor or function object
See also
Using a Controller design pattern to communicate with processing modules
Getting ready
How to do it…
How it works…
There's more…
The Model-View-Controller architecture
Converting color representations
Getting ready
How to do it…
How it works…
See also
Representing colors with hue, saturation, and brightness
How to do it…
How it works…
There's more…
Using colors for detection – skin tone detection
4. Counting the Pixels with Histograms
Introduction
Computing the image histogram
Getting started
How to do it...
How it works...
There's more...
Computing histograms of color images
See also
Applying look-up tables to modify the image appearance
How to do it...
How it works...
There's more...
Stretching a histogram to improve the image contrast
Applying a look-up table on color images
See also
Equalizing the image histogram
How to do it...
How it works...
Backprojecting a histogram to detect specific image content
How to do it...
How it works...
There's more...
Backprojecting color histograms
See also
Using the mean shift algorithm to find an object
How to do it...
How it works...
See also
Retrieving similar images using the histogram comparison
How to do it...
How it works...
See also
Counting pixels with integral images
How to do it...
How it works...
There's more...
Adaptive thresholding
Visual tracking using histograms
See also
5. Transforming Images with Morphological Operations
Introduction
Eroding and dilating images using morphological filters
Getting ready
How to do it...
How it works...
There's more...
See also
Opening and closing images using morphological filters
How to do it...
How it works...
See also
Detecting edges and corners using morphological filters
Getting ready
How to do it...
How it works...
See also
Segmenting images using watersheds
How to do it...
How it works...
There's more...
See also
Extracting distinctive regions using MSER
How to do it...
How it works...
See also
Extracting foreground objects with the GrabCut algorithm
How to do it...
How it works...
See also
6. Filtering the Images
Introduction
Filtering images using low-pass filters
How to do it...
How it works...
There's more...
Downsampling an image
Interpolating pixel values
See also
Filtering images using a median filter
How to do it...
How it works...
Applying directional filters to detect edges
How to do it...
How it works...
There's more...
Gradient operators
Gaussian derivatives
See also
Computing the Laplacian of an image
How to do it...
How it works...
There's more...
Enhancing the contrast of an image using the Laplacian
Difference of Gaussians
See also
7. Extracting Lines, Contours, and Components
Introduction
Detecting image contours with the Canny operator
How to do it...
How it works...
See also
Detecting lines in images with the Hough transform
Getting ready
How to do it...
How it works...
There's more...
Detecting circles
See also
Fitting a line to a set of points
How to do it...
How it works...
There's more...
Extracting the components' contours
How to do it...
How it works...
There's more...
Computing components' shape descriptors
How to do it...
How it works...
There's more...
Quadrilateral detection
8. Detecting Interest Points
Introduction
Detecting corners in an image
How to do it...
How it works...
There's more...
Good features to track
The feature detector's common interface
See also
Detecting features quickly
How to do it...
How it works...
There's more...
Adapted feature detection
Grid adapted feature detection
Pyramid adapted feature detection
See also
Detecting scale-invariant features
How to do it...
How it works...
There's more...
The SIFT feature-detection algorithm
See also
Detecting FAST features at multiple scales
How to do it...
How it works...
There's more...
The ORB feature-detection algorithm
See also
9. Describing and Matching Interest Points
Introduction
Matching local templates
How to do it...
How it works...
There's more...
Template matching
See also
Describing local intensity patterns
How to do it...
How it works...
There's more...
Cross-checking matches
The ratio test
Distance thresholding
See also
Describing keypoints with binary features
How to do it...
How it works...
There's more...
FREAK
See also
10. Estimating Projective Relations in Images
Introduction
Image formation
Calibrating a camera
How to do it...
How it works...
There's more...
Calibration with known intrinsic parameters
Using a grid of circles for calibration
See also
Computing the fundamental matrix of an image pair
Getting ready
How to do it...
How it works...
See also
Matching images using a random sample consensus
How to do it...
How it works...
There's more...
Refining the fundamental matrix
Refining the matches
Computing a homography between two images
Getting ready
How to do it...
How it works...
There's more...
Detecting planar targets in an image
See also
11. Processing Video Sequences
Introduction
Reading video sequences
How to do it...
How it works...
There's more...
See also
Processing the video frames
How to do it...
How it works...
There's more...
Processing a sequence of images
Using a frame processor class
See also
Writing video sequences
How to do it...
How it works...
There's more...
The codec four-character code
See also
Tracking feature points in a video
How to do it...
How it works...
See also
Extracting the foreground objects in a video
How to do it...
How it works...
There's more...
The Mixture of Gaussian method
See also
Index
OpenCV Computer Vision Application Programming Cookbook Second Edition
OpenCV Computer Vision Application Programming Cookbook Second Edition
Copyright © 2014 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: May 2011
Second edition: August 2014
Production reference: 1200814
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78216-148-6
www.packtpub.com
Cover image by Mathieu Paquette (<mathieu.paquette@live.ca>)
Credits
Author
Robert Laganière
Reviewers
Walter Lucetti
Anton Sukhinov
Tao Wu
Commissioning Editor
Usha Iyer
Acquisition Editors
Usha Iyer
Neha Nagwekar
Content Development Editor
Amey Varangaonkar
Technical Editors
Indrajit A. Das
Pooja Nair
Humera Shaikh
Copy Editors
Dipti Kapadia
Stuti Srivastava
Project Coordinator
Leena Purkait
Proofreaders
Simran Bhogal
Maria Gould
Ameesha Green
Paul Hindle
Indexer
Hemangini Bari
Graphics
Sheetal Aute
Disha Haria
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
About the Author
Robert Laganière is a professor at the School of Electrical Engineering and Computer Science of the University of Ottawa, Canada. He is also a faculty member of the VIVA research lab and is the co-author of several scientific publications and patents in content-based video analysis, visual surveillance, object recognition, and 3D reconstruction.
Robert authored OpenCV2 Computer Vision Application Programming Cookbook, Packt Publishing, in 2011 and co-authored Object Oriented Software Development, McGraw Hill, in 2001. He co-founded Visual Cortek in 2006, an Ottawa-based video analytics startup that was later acquired by iWatchLife (www.iwatchlife.com) in 2009, where he also assumes the role of Chief Scientist. Since 2011, he is also Chief Scientist at Cognivue Corp, which is a leader in embedded vision solutions. He has a Bachelor of Electrical Engineering degree from Ecole Polytechnique in Montreal (1987) and MSc and PhD degrees from INRS-Telecommunications, Montreal (1996). You can visit his website at www.laganiere.name.
I wish to thank all my students at the VIVA lab; I learn so much from them.
About the Reviewers
Walter Lucetti, known on the Internet as Myzhar, is an Italian computer engineer with a specialization in Robotics and Robotics Perception. He received a Laurea degree in 2005 while studying at Research Center E.Piaggio
in Pisa (Italy). He wrote a thesis on the 3D mapping of the real world using a 2D Laser tilted using a servo motor, fusing 3D with RGB data. During the writing of his thesis, he got introduced to OpenCV for the first time. It was early 2004 and OpenCV was at its larval stage.
After the Laurea, he started working as a software developer for low-level embedded systems and high-level desktop systems. He deeply improved his knowledge about Computer Vision and Machine Learning as a researcher at Gustavo Stefanini Advanced Robotics Research Center in La Spezia (Italy), which is a spinoff of PERCRO Laboratory of the Scuola Superiore Sant'Anna of Pisa (Italy).
Now, he is working in the industry, developing firmware for embedded ARM systems and intelligent algorithms for video surveillance systems.
He is also working on a personal project: MyzharBot. MyzharBot is a tracked ground mobile robot that uses stereo vision to detect obstacles and analyze and explore the environment.
You can find more information about Walter, his project, and a lot of tutorials on computer vision at www.robot-home.it and http://myzharbot.robot-home.it.
Anton Sukhinov graduated from Moscow Institute of Physics and Technology. He has a PhD degree in Physics and Mathematics.
Anton has experience in mathematical modeling, numerical simulation, image processing and analysis, machine learning, and electronics.
During the reviewing of this book, Anton was a senior developer in CVisionLab, which is a small Russian R&D firm dedicated to image processing, analysis, machine learning, and related fields.
Currently, he works as a research scientist at Skolkovo Institute of Science and Technology (Russia).
Tao Wu graduated from University of Maryland with a PhD degree in Electrical Engineering in 2013. He received his MS and BE degrees in Electrical Engineering from Tsinghua University, Beijing, in 2008 and 2005, respectively.
He has more than 7 years of experience in C/C++ and OpenCV. His research interests include computer vision, pattern recognition, machine learning, and image and video processing.
Currently, he is working for Microsoft.
www.PacktPub.com
Support files, eBooks, discount offers, and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
Fully searchable across every book published by Packt
Copy and paste, print and bookmark content
On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Preface
OpenCV (Open source Computer Vision) is an open source library that contains more than 500 optimized algorithms for image and video analysis. Since its introduction in 1999, it has been largely adopted as the primary development tool by the community of researchers and developers in computer vision. OpenCV was originally developed at Intel by a team led by Gary Bradski as an initiative to advance research in vision and promote the development of rich vision-based, CPU-intensive applications. After a series of beta releases, Version 1.0 was launched in 2006. A second major release occurred in 2009 with the launch of OpenCV 2 that proposed important changes, especially the new C++ interface that we use in this book. In 2012, OpenCV reshaped itself as a nonprofit foundation (http://opencv.org/) that relies on crowdfunding for its future development.
This book is a new edition of OpenCV Computer Vision Application Programming Cookbook. All the programming recipes of the previous editions have been reviewed and updated. We also have added new content to provide readers with even better coverage of the essential functionalities of the library. This book covers many of the library's features and shows you how to use them to accomplish specific tasks. Our objective is not to provide detailed coverage of every option offered by the OpenCV functions and classes, but rather to give you the elements you need to build your applications from the ground up. In this book, we also explore fundamental concepts in image analysis, and we describe some of the important algorithms in computer vision.
This book is an opportunity for you to get introduced to the world of image and video analysis. However, this is just the beginning. The good news is that OpenCV continues to evolve and expand. Just consult the OpenCV online documentation at http://opencv.org/ to stay updated on what the library can do for you. You can also visit the author's website at www.laganiere.name for updated information about this Cookbook.
What this book covers
Chapter 1, Playing with Images, introduces the OpenCV library and shows you how to build simple applications that can read and display images. It also introduces the basic OpenCV data structures.
Chapter 2, Manipulating Pixels, explains how an image can be read. It describes different methods for scanning an image in order to perform an operation on each of its pixels.
Chapter 3, Processing Color Images with Classes, consists of recipes that present various object-oriented design patterns that can help you build better computer vision applications. It also discusses the concept of colors in images.
Chapter 4, Counting the Pixels with Histograms, shows you how to compute image histograms and how they can be used to modify an image. Different applications based on histograms are presented, and they achieve image segmentation, object detection, and image retrieval.
Chapter 5, Transforming Images with Morphological Operations, explores the concept of mathematical morphology. It presents different operators and informs you how they can be used to detect edges, corners, and segments in images.
Chapter 6, Filtering the Images, teaches you the principle of frequency analysis and image filtering. It shows how low-pass and high-pass filters can be applied to images and presents the concept of derivative operators.
Chapter 7, Extracting Lines, Contours, and Components, focuses on the detection of geometric image features. It explains how to extract contours, lines, and connected components in an image.
Chapter 8, Detecting Interest Points, describes various feature-point detectors in images.
Chapter 9, Describing and Matching Interest Points, explains how descriptors of interest points can be computed and used to match points between images.
Chapter 10, Estimating Projective Relations in Images, explores the projective relations that exist between two images of the same scene. It also describes the process of camera calibration and revisits the problem of matching feature points.
Chapter 11, Processing Video Sequences, provides you with a framework to read and write a video sequence and process its frames. It also shows you how it is possible to track feature points from frame to frame and how to extract the foreground objects moving in front of a camera.
What you need for this book
This Cookbook is based on the C++ API of the OpenCV library. Therefore, it is assumed that you have some experience with the C++ language. In order to run the examples presented in the recipes and experiment with them, you need a good C++ development environment. Microsoft Visual Studio and Qt are two popular choices.
Who this book is for
This Cookbook is appropriate for novice C++ programmers who want to learn how to use the OpenCV library to build computer vision applications. It is also suitable for professional software developers who wish to be introduced to the concepts of computer vision programming. It can be used as a companion book for university-level computer vision courses. It is an excellent reference for graduate students and researchers of image processing and computer vision.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, folder names, filenames, file extensions, pathnames, dummy URLs, and user input are shown as follows: Very conveniently, this check is encapsulated inside the create method of cv::Mat.
A block of code is set as follows:
// use image with a Mat_ template
cv::Mat_
im2(50,100)= 0; // access to row 50 and column 100
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com> if you are having a problem with any aspect of the book, and we will do our best to address it.
Chapter 1. Playing with Images
In this chapter, we will get you started with the OpenCV library. You will learn how to perform the following tasks:
Installing the OpenCV library
Loading, displaying, and saving images
Exploring the cv::Mat data structure
Defining regions of interest
Introduction
This chapter will teach you the basic elements of OpenCV and will show you how to accomplish the most fundamental image processing tasks: reading, displaying, and saving images. However, before you can start with OpenCV, you need to install the library. This is a simple process that is explained in the first recipe of this chapter.
All your computer vision applications will involve the processing of images. This is why the most fundamental tool that OpenCV offers you is a data structure to handle images and matrices. It is a powerful data structure, with many useful attributes and methods. It also incorporates an advanced memory management model that greatly facilitates the development of applications. The last two recipes of this chapter will teach you how to use this important data structure of OpenCV.
Installing the OpenCV library
OpenCV is an open source library for developing computer vision applications that run on Windows, Linux, Android, and Mac OS. It can be used in both academic and commercial applications under a BSD license that allows you to freely use, distribute, and adapt it. This recipe will show you how to install the library on your machine.
Getting ready
When you visit the OpenCV official website at http://opencv.org/, you will find the latest release of the library, the online documentation, and many other useful resources on OpenCV.
How to do it...
From the OpenCV website, go to the DOWNLOADS page that corresponds to the platform of your choice (Unix/Windows or Android). From there, you will be able to download the OpenCV package. You will then need to uncompress it, normally under a directory with a name that corresponds to the library version (for example, in Windows, you can save the uncompressed directory under C:\OpenCV2.4.9). Once this is done, you will find a collection of files and directories that constitute the library at the chosen location. Notably, you will find the sources directory here, which contains all the source files. (Yes, it is open source!) However, in order to complete the installation of the library and have it ready for use, you need to undertake an additional step: generating the binary files of the library for the environment of your choice. This is indeed the point where you have to make a decision on the target platform that you will use to create your OpenCV applications. Which operating system should you use? Windows or Linux? Which compiler should you use? Microsoft VS2013 or MinGW? 32-bit or 64-bit? The Integrated Development Environment (IDE) that you will use in your project development will also guide you to make these choices.
Note that if you are working under Windows with Visual Studio, the executable installation package will, most probably, not only install the library sources, but also install all of the precompiled binaries needed to build your applications. Check for the build directory; it should contain the x64 and x86 subdirectories (corresponding to the 64-bit and 32-bit versions). Within these subdirectories, you should find directories such as vc10, vc11, and vc12; these contain the binaries for the different versions of MS Visual Studio. In that case, you are ready to start using OpenCV. Therefore, you can skip the compilation step described in this recipe, unless you want a customized build with specific options.
To complete the installation process and build the OpenCV binaries, you need to use the CMake tool, available at http://cmake.org. CMake is another open source software tool designed to control the compilation process of a software system using platform-independent configuration files. It generates the required makefiles or workspaces needed for compiling a software library in your environment. Therefore, you need to download and install CMake. You can then run it using the command line, but it is easier to use CMake with its GUI (cmake-gui). In the latter case, all you need to do is specify the folder containing the OpenCV library source and the one that will contain the binaries. You need to click on Configure in order to select the compiler of your choice and then click on Configure again.
You are now ready to generate your project files by clicking on the Generate button. These files will allow you to compile the library. This is the last step of the installation process, which will make the library ready to be used under your development environment. For example, if you have selected Visual Studio, then all you need to do is to open the top-level solution file that CMake has created for you (most probably, the OpenCV.sln file). You then issue the Build Solution command in Visual Studio. To get both a Release and a Debug build, you will have to repeat the compilation process twice, one for each configuration. The bin directory that is created contains the dynamic library files that your executable will call at runtime. Make sure to set your system PATH environment variable from the control panel such that your operating system can find the dll files when you run your applications.
In Linux environments, you will use the generated makefiles by running your make utility command. To complete the installation of all the directories, you also have to run a Build INSTALL or sudo make INSTALL command.
However, before you build the libraries, make sure to check what the OpenCV installer has installed for you; the built library that you are looking for might already be there, which will save you the compilation step. If you wish to use Qt as your IDE, the There's more... section of this recipe describes an alternative way to compile the OpenCV project.
How it works...
Since Version 2.2, the OpenCV library is divided into several modules. These modules are built-in library files located in the lib directory. Some of the commonly-used modules are as follows:
The opencv_core module that contains the core functionalities of the library, in particular, basic data structures and arithmetic functions
The opencv_imgproc module that contains the main image processing functions
The opencv_highgui module that contains the image and video reading and writing functions along with some user interface functions
The opencv_features2d module that contains the feature point detectors and descriptors and the feature point matching framework
The opencv_calib3d module that contains the camera calibration, two-view geometry estimation, and stereo functions
The opencv_video module that contains the motion estimation, feature tracking, and foreground extraction functions and classes
The opencv_objdetect module that contains the object detection functions such as the face and people detectors
The library also includes other utility modules that contain machine learning functions (opencv_ml), computational geometry algorithms (opencv_flann), contributed code (opencv_contrib), obsolete code (opencv_legacy), and gpu-accelerated code (opencv_gpu). You will also find other specialized libraries that implement higher-level functions, such as opencv_photo for computational photography and opencv_stitching for image-stitching algorithms. There is also a library module, called opencv_nonfree, which contains functions that have a potential limitation in use. When you compile your application, you will have to link your program with the libraries that contain the OpenCV functions you are using. Most likely, these will be the first three functions of the list given previously plus some of the others depending on the scope of your application.
All these modules have a header file associated with them (located in the include directory). A typical OpenCV C++ code will, therefore, start by including the required