Chapter 2. Introduction to OpenCV

Getting Started

After installing the OpenCV library, our first task is, naturally, to get started and make something interesting happen. In order to do this, we will need to set up the programming environment.

In Visual Studio, it is necessary to create a project and to configure the setup so that (a) the libraries highgui.lib, cxcore.lib, ml.lib, and cv.lib are linked[8] and (b) the preprocessor will search the OpenCV …/opencv/*/include directories for header files. These “include” directories will typically be named something like C:/program files/opencv/cv/include,[9] …/opencv/cxcore/include, …/opencv/ml/include, and …/opencv/otherlibs/highgui. Once you’ve done this, you can create a new C file and start your first program.


Certain key header files can make your life much easier. Many useful macros are in the header files …/opencv/cxcore/include/cxtypes.h and cxmisc.h. These can do things like initialize structures and arrays in one line, sort lists, and so on. The most important headers for compiling are …/cv/include/cv.h and …/cxcore/include/cxcore.h for computer vision, …/otherlibs/highgui/highgui.h for I/O, and …/ml/include/ml.h for machine learning.

First Program—Display a Picture

OpenCV provides utilities for reading from a wide array of image file types as well as from video and cameras. These utilities are part of a toolkit called HighGUI, which is included in the OpenCV package. We will use some of these utilities to create a simple program ...

Get Learning OpenCV now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.