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.

Tip

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.

[8] For debug builds, you should link to the libraries highguid.lib, cxcored.lib, mld.lib, and cvd.lib

[9] C:/program files/ is the default installation of the OpenCV directory on Windows, although you can choose to install it elsewhere. To avoid confusion, from here on we'll ...

Get Learning OpenCV now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.