next_inactive up previous

Introduction to programming with OpenCV

Gady Agam

Department of Computer Science
Illinois Institute of Technology

January 27, 2006


The purpose of this document is to get you started quickly with OpenCV without having to go through lengthy reference manuals. Once you understand these basics you will be able to consult the OpenCV manuals on a need basis.



Description of OpenCV


OpenCV naming conventions

Compilation instructions

Example C Program

// hello-world.cpp
// This is a simple, introductory OpenCV program. The program reads an
// image from a file, inverts it, and displays the result.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
IplImage* img = 0;
int height,width,step,channels;
uchar *data;
int i,j,k;

printf("Usage: main <image-file-name>\n\7");

// load an image
printf("Could not load image file: %s\n",argv[1]);

// get the image data
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);

// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);

// invert the image
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)

// show the image
cvShowImage("mainWin", img );

// wait for a key

// release the image
cvReleaseImage(&img );
return 0;

GUI commands

Window management

Input handling

Basic OpenCV data structures

Image data structure

Matrices and vectors

Other data structures

Working with images

Allocating and releasing images

Reading and writing images

Accessing image elements

Image conversion

Drawing commands

Working with matrices

Allocating and releasing matrices

Accessing matrix elements

Matrix/vector operations

Working with video sequences

Capturing a frame from a video sequence

Getting/setting frame information

Saving a video file

next_inactive up previous
Gady Agam 2006-03-31