The Opencv Tutorials Release 2.4.9.0
Total Page:16
File Type:pdf, Size:1020Kb
The OpenCV Tutorials Release 2.4.9.0 June 25, 2014 CONTENTS 1 Introduction to OpenCV 5 1.1 Installation in Linux...........................................9 1.2 Using OpenCV with gcc and CMake.................................. 10 1.3 Using OpenCV with Eclipse (plugin CDT)............................... 12 1.4 Installation in Windows......................................... 18 1.5 How to build applications with OpenCV inside the Microsoft Visual Studio .............. 28 1.6 Image Watch: viewing in-memory images in the Visual Studio debugger............... 34 1.7 Introduction to Java Development.................................... 39 1.8 Using OpenCV Java with Eclipse.................................... 48 1.9 Introduction to OpenCV Development with Clojure.......................... 57 1.10 Introduction into Android Development................................. 69 1.11 OpenCV4Android SDK......................................... 96 1.12 Android Development with OpenCV.................................. 106 1.13 Installation in iOS............................................ 118 1.14 Cross compilation for ARM based Linux systems............................ 118 1.15 Load and Display an Image....................................... 120 1.16 Load, Modify, and Save an Image.................................... 123 1.17 How to write a tutorial for OpenCV................................... 125 2 core module. The Core Functionality 135 2.1 Mat - The Basic Image Container.................................... 137 2.2 How to scan images, lookup tables and time measurement with OpenCV............... 143 2.3 Mask operations on matrices....................................... 148 2.4 Adding (blending) two images using OpenCV............................. 150 2.5 Changing the contrast and brightness of an image!........................... 152 2.6 Basic Drawing.............................................. 156 2.7 Random generator and text with OpenCV................................ 161 2.8 Discrete Fourier Transform....................................... 165 2.9 File Input and Output using XML and YAML files........................... 169 2.10 Interoperability with OpenCV 1..................................... 176 3 imgproc module. Image Processing 181 3.1 Smoothing Images............................................ 186 3.2 Eroding and Dilating........................................... 191 3.3 More Morphology Transformations................................... 197 3.4 Image Pyramids............................................. 203 3.5 Basic Thresholding Operations..................................... 209 3.6 Making your own linear filters!..................................... 217 3.7 Adding borders to your images..................................... 221 i 3.8 Sobel Derivatives............................................. 225 3.9 Laplace Operator............................................. 231 3.10 Canny Edge Detector........................................... 235 3.11 Hough Line Transform.......................................... 240 3.12 Hough Circle Transform......................................... 246 3.13 Remapping................................................ 250 3.14 Affine Transformations.......................................... 256 3.15 Histogram Equalization......................................... 262 3.16 Histogram Calculation.......................................... 268 3.17 Histogram Comparison.......................................... 275 3.18 Back Projection............................................. 280 3.19 Template Matching............................................ 286 3.20 Finding contours in your image..................................... 294 3.21 Convex Hull............................................... 295 3.22 Creating Bounding boxes and circles for contours............................ 297 3.23 Creating Bounding rotated boxes and ellipses for contours....................... 300 3.24 Image Moments............................................. 302 3.25 Point Polygon Test............................................ 304 4 highgui module. High Level GUI and Media 307 4.1 Adding a Trackbar to our applications!................................. 308 4.2 Video Input with OpenCV and similarity measurement......................... 311 4.3 Creating a video with OpenCV..................................... 319 5 calib3d module. Camera calibration and 3D reconstruction 325 5.1 Camera calibration with square chessboard............................... 326 5.2 Camera calibration With OpenCV.................................... 326 6 feature2d module. 2D Features framework 337 6.1 Feature Description........................................... 339 6.2 Harris corner detector.......................................... 341 6.3 Feature Matching with FLANN..................................... 345 6.4 Features2D + Homography to find a known object........................... 348 6.5 Shi-Tomasi corner detector........................................ 351 6.6 Creating yor own corner detector.................................... 353 6.7 Detecting corners location in subpixeles................................. 357 6.8 Feature Detection............................................. 360 6.9 Feature Matching with FLANN..................................... 362 6.10 Features2D + Homography to find a known object........................... 365 6.11 Detection of planar objects........................................ 368 7 video module. Video analysis 371 8 objdetect module. Object Detection 373 8.1 Cascade Classifier............................................ 374 9 ml module. Machine Learning 379 9.1 Introduction to Support Vector Machines................................ 380 9.2 Support Vector Machines for Non-Linearly Separable Data....................... 385 10 gpu module. GPU-Accelerated Computer Vision 393 10.1 Similarity check (PNSR and SSIM) on the GPU............................ 394 11 contrib module. The additional contributions made available ! 403 11.1 Discovering the human retina and its use for image processing..................... 404 ii 12 OpenCV iOS 417 12.1 OpenCV iOS Hello............................................ 418 12.2 OpenCV iOS - Image Processing.................................... 422 12.3 OpenCV iOS - Video Processing.................................... 424 13 OpenCV Viz 431 13.1 Launching Viz.............................................. 432 13.2 Pose of a widget............................................. 434 13.3 Transformations............................................. 436 13.4 Creating Widgets............................................. 440 14 General tutorials 445 iii iv The OpenCV Tutorials, Release 2.4.9.0 The following links describe a set of basic OpenCV tutorials. All the source code mentioned here is provide as part of the OpenCV regular releases, so check before you start copy & pasting the code. The list of tutorials below is automatically generated from reST files located in our GIT repository. As always, we would be happy to hear your comments and receive your contributions on any tutorial. • Introduction to OpenCV You will learn how to setup OpenCV on your computer! • core module. The Core Functionality Here you will learn the about the basic building blocks of the library. A must read and know for understanding how to manipulate the images on a pixel level. • imgproc module. Image Processing In this section you will learn about the image processing (manipulation) functions inside OpenCV. • highgui module. High Level GUI and Media This section contains valuable tutorials about how to read/save your im- age/video files and how to use the built-in graphical user interface of the library. • calib3d module. Camera calibration and 3D reconstruction Although we got most of our images in a 2D format they do come from a 3D world. Here you will learn how to find out from the 2D images information about the 3D world. • feature2d module. 2D Features framework CONTENTS 1 The OpenCV Tutorials, Release 2.4.9.0 Learn about how to use the feature points detectors, descriptors and match- ing framework found inside OpenCV. • video module. Video analysis Look here in order to find use on your video stream algorithms like: motion extraction, feature tracking and foreground extractions. • objdetect module. Object Detection Ever wondered how your digital camera detects peoples and faces? Look here to find out! • ml module. Machine Learning Use the powerfull machine learning classes for statistical classification, re- gression and clustering of data. • gpu module. GPU-Accelerated Computer Vision Squeeze out every little computation power from your system by using the power of your video card to run the OpenCV algorithms. • contrib module. The additional contributions made available ! Discover additional contribution to OpenCV. • OpenCV iOS 2 CONTENTS The OpenCV Tutorials, Release 2.4.9.0 Run OpenCV and your vision apps on an iDevice • OpenCV Viz These tutorials show how to use Viz module effectively. • General tutorials These tutorials are the bottom of the iceberg as they link together multiple of the modules presented above in order to solve complex problems. CONTENTS 3 The OpenCV Tutorials, Release 2.4.9.0 4 CONTENTS CHAPTER ONE INTRODUCTION TO OPENCV Here you can read tutorials about how to set up your computer to work with the OpenCV library. Additionally you can find a few very basic sample source code that will let introduce you to the world of the OpenCV. • Linux Title: Installation in Linux Compatibility: > OpenCV 2.0 Author: Ana Huamán