This page contains a very soft and gentle introduction to OpenCV version 1.0.0. The OpenCV library is a powerful Image Processing and Computer Vision library written in C. The OpenCV homepage is [http://www.intel.com/technology/computing/opencv/index.htm here], and the project had a nice [http://opencvlibrary.sourceforge.net/ wiki] as well.

In general, OpenCV is quite well-documented, so this page only provides some very simple examples to get you started. Due to the size of the OpenCV library, the documentation can be somewhat convoluted so you have to know what you are looking for. But don't worry, you'll quickly pick that up.

* '''cxcore''' provides a set of basic data structures. This includes 'images', 'matrices', 'points', and so forth. Besides this, '''cxcore''' also contains basic drawing functionality that allows you to draw lines, circles, etc, in images.

* '''highgui''' contains functions for building graphical user interfaces and for reading and writing images. That is, it contains functions that allows you to show images, and acquite them from either the disc or from a camera.

One of the major strengths of OpenCV is its ease of use. Each of the three core parts of OpenCV has one header file that you should include in your C program. These are called: "cxcore.h", "cv.h" and "highgui.h".

-

OpenCV, benyttes programmet ''pkg-config''. . Kommandoen

+

To compile OpenCV programs you can use the ''pkg-config'' program. This simple provides you with the necesary compiler and linker flags. The command

pkg-config --cflags opencv

pkg-config --cflags opencv

-

, mens kommandoen

+

prints the list of arguments needed to allow the compiler to find the header files, while

pkg-config --libs opencv

pkg-config --libs opencv

-

. Makefile. .

+

prints the commands needed for linking. This makes it very easy to write Makefile's for your project. The following simple example shows how (you'll need to adapt it to your own programs).

# Compile and link flags

# Compile and link flags

-

CXX = g++

+

CXX = g++

-

CXXFLAGS = `pkg-config opencv --cflags` -Wall

+

CFLAGS = -Wall -g

-

LIBS = `pkg-config opencv --libs`

+

-

# Name of executable

+

# Compilation (add flags as needed)

-

EXECUTABLE = myprogram

+

CXXFLAGS += `pkg-config opencv --cflags`

-

# Files

+

# Linking (add flags as needed)

-

SOURCES = myprogram.cc myauxilaryfunction.cc

+

LDFLAGS += `pkg-config opencv --libs`

-

OBJECTS = $(patsubst %.cc, %.o, $(SOURCES))

+

-

# Linking

+

# Name your target executables here

-

all: $(OBJECTS)

+

all = test

-

$(CXX) $(LIBS) $(OBJECTS) -o $(EXECUTABLE)

+

-

# Compilation

+

# Default target is the first one - so we will have it make everything :-)

In the first example we'll grab images from a camera and show it on the screen. This is a very simple, yet quite usable, OpenCV program. The program can be found the Robot Eksperimentariums [[Robot_Eksperimentarium_2007#The_SVN_Repository|SVN]] under ''Examples/opencv/Eksempel1'' and consists of the file ''eksempel1.cc'' and a corrsponding ''Makefile''.

Latest revision as of 18:56, 25 August 2015

This page contains a very soft and gentle introduction to OpenCV version 1.0.0. The OpenCV library is a powerful Image Processing and Computer Vision library written in C. The OpenCV homepage is here, and the project had a nice wiki as well.

In general, OpenCV is quite well-documented, so this page only provides some very simple examples to get you started. Due to the size of the OpenCV library, the documentation can be somewhat convoluted so you have to know what you are looking for. But don't worry, you'll quickly pick that up.

The OpenCV Structure

OpenCV consists of three core parts

cxcore provides a set of basic data structures. This includes 'images', 'matrices', 'points', and so forth. Besides this, cxcore also contains basic drawing functionality that allows you to draw lines, circles, etc, in images.

highgui contains functions for building graphical user interfaces and for reading and writing images. That is, it contains functions that allows you to show images, and acquite them from either the disc or from a camera.

How to use OpenCV on Linux

One of the major strengths of OpenCV is its ease of use. Each of the three core parts of OpenCV has one header file that you should include in your C program. These are called: "cxcore.h", "cv.h" and "highgui.h".

To compile OpenCV programs you can use the pkg-config program. This simple provides you with the necesary compiler and linker flags. The command

pkg-config --cflags opencv

prints the list of arguments needed to allow the compiler to find the header files, while

pkg-config --libs opencv

prints the commands needed for linking. This makes it very easy to write Makefile's for your project. The following simple example shows how (you'll need to adapt it to your own programs).

Example 1

In the first example we'll grab images from a camera and show it on the screen. This is a very simple, yet quite usable, OpenCV program. The program can be found the Robot Eksperimentariums SVN under Examples/opencv/Eksempel1 and consists of the file eksempel1.cc and a corrsponding Makefile.