In today's digital world, images and videos are everywhere, and with the advent of powerful and affordable computing devices, it has never been easier to create sophisticated imaging applications. Plentiful software tools and libraries manipulating images and videos are offered, but for anyone who wishes to develop his/her own applications, the OpenCV library is the tool to use.
OpenCV (Open Source Computer Vision) is an open source library containing 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 which we use in this book. At the time of writing, the latest release is 2.2 (December 2010).
This book covers many of the library's features and shows how to use them to accomplish specific tasks. Our objective is not to provide a complete and 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 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. But this is just the beginning. The good news is that OpenCV continues to evolve and expand. Just consult the OpenCV online documentation to stay updated about what the library can do for you:
http://opencv.willowgarage.com/wiki/
Chapter 1, Playing with Images, introduces the OpenCV library and shows you how to run simple applications using the MS Visual C++ and Qt development environments.
Chapter 2, Manipulating the 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. You will also learn how to define region of interest inside an image.
Chapter 3, Processing Images with Classes, consists of recipes which present various object-oriented design patterns that can help you to build better computer vision applications.
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 that 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 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. It presents the two image derivative operators: the gradient and the Laplacian.
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 and Matching Interest Points, describes various feature point detectors in images. It also explains how descriptors of interest points can be computed and used to match points between images.
Chapter 9, Estimating Projective Relations in Images, analyzes the different relations involved in image formation. It also explores the projective relations that exist between two images of a same scene.
Chapter 10, Processing Video Sequences, provides a framework to read and write a video sequence and to 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.
If you are a novice C++ programer who wants to learn how to use the OpenCV library to build computer vision applications, then this cookbook is appropriate for you. It is also suitable for professional software developers wishing to be introduced to the concepts of computer vision programming. It can be used as a companion book in university-level computer vision courses. It constitutes an excellent reference for graduate students and researchers in image processing and computer vision. The book provides a good combination of basic to advanced recipes. Basic knowledge of C++ is required.
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 are shown as follows: "We can include other contexts through the use of the include
directive."
A block of code is set as follows:
// get the iterators cv::Mat_<cv::Vec3b>::const_iterator it= image.begin<cv::Vec3b>();
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
// Converting to Lab color space
cv::cvtColor(image, converted, CV_BGR2Lab);
// get the iterators of the converted image
cv::Mat_<cv::Vec3b>::iterator it=
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "This value is read when the Process button is clicked, which also triggers the processing and displays the result".
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 <[email protected]>
, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>
.
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.
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.
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.
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/support, 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 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 <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.