Opencv Tutorials

  • View
    8

  • Download
    2

Embed Size (px)

Transcript

  • 5/20/2018 Opencv Tutorials

    1/233

    The OpenCV Tutorials

    Release 2.3

    July 21, 2011

  • 5/20/2018 Opencv Tutorials

    2/233

  • 5/20/2018 Opencv Tutorials

    3/233

    CONTENTS

    1 Introduction to OpenCV 3

    1.1 Installation in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    1.2 Using OpenCV with gcc and CMake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    1.3 Using OpenCV with Eclipse (plugin CDT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    1.4 Installation in Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    1.5 How to build applications with OpenCV inside theMicrosoft Visual Studio . . . . . . . . . . . . . . 24

    1.6 Using Android binary package with Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

    1.7 Load and Display an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

    1.8 Load, Modify, and Save an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

    2 coremodule. The Core Functionality 47

    2.1 Mat - The Basic Image Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    2.2 How to scan images, lookup tables and time measurement with OpenCV . . . . . . . . . . . . . . . 54

    2.3 Adding (blending) two images using OpenCV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

    2.4 Changing the contrast and brightness of an image! . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    2.5 Basic Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

    2.6 Fancy Drawing! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    2.7 Mask operations on matrixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

    3 imgprocmodule. Image Processing 73

    3.1 Smoothing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

    3.2 Eroding and Dilating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

    3.3 More Morphology Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

    3.4 Image Pyramids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

    3.5 Basic Thresholding Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

    3.6 Making your own linear filters! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

    3.7 Adding borders to your images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

    3.8 Sobel Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

    3.9 Laplace Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

    3.10 Canny Edge Detector. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

    3.11 Hough Line Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

    3.12 Hough Circle Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

    3.13 Remapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

    3.14 Affine Transformations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

    3.15 Histogram Equalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

    3.16 Histogram Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

    3.17 Histogram Comparison. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

    3.18 Back Projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

    3.19 Template Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

    i

  • 5/20/2018 Opencv Tutorials

    4/233

    3.20 Finding contours in your image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

    3.21 Convex Hull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

    3.22 Creating Bounding boxes and circles for contours. . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

    3.23 Creating Bounding rotated boxes and ellipses for contours . . . . . . . . . . . . . . . . . . . . . . . 191

    3.24 Image Moments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

    3.25 Point Polygon Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196

    4 highguimodule. High Level GUI and Media 199

    4.1 Adding a Trackbar to our applications! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

    5 calib3dmodule. Camera calibration and 3D reconstruction 205

    6 feature2dmodule. 2D Features framework 207

    6.1 Harris corner detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

    6.2 Shi-Tomasi corner detector. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

    6.3 Creating yor own corner detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

    6.4 Detecting corners location in subpixeles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

    7 videomodule. Video analysis 221

    8 objdetectmodule. Object Detection 223

    9 mlmodule. Machine Learning 225

    10 gpumodule. GPU-Accelerated Computer Vision 227

    11 General tutorials 229

    ii

  • 5/20/2018 Opencv Tutorials

    5/233

    The OpenCV Tutorials, Release 2.3

    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 SVN 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 3Dworld. Here you will learn how to find out from the 2D images information

    about the 3D world.

    feature2d module. 2D Features framework

    CONTENTS 1

  • 5/20/2018 Opencv Tutorials

    6/233

    The OpenCV Tutorials, Release 2.3

    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 algoritms 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 Lea