OpenCV Structure and Content (Overview)

OpenCV is broadly structured into five main components, four of which are shown in figure below.


CV component contains the basic image processing and higher-level computer vision algorithms.
ML is the machine learning library, which includes many statistical classifiers and clustering tools.
HighGUI contains I/O routines and functions for storing and loading video and images.
CXCore contains the basic data structures and content.

Another component is CvAux, which contains both defunct areas (embedded HMM face recognition) and experimental algorithms (background/foreground segmentation).

(from “Learning OpenCV” by G. Bradski and A. Kaehler)

You can found documentation for content of component in ..\OpenCV2.0\doc\opencv.pdf. Here below is the general view of each components, including non-main component.

CXCORE

Basic Structures
Operations on Arrays
Dynamic Structures
Drawing Functions
Data Persistence and RTTI
Miscellaneous Functions
Error Handling and System Functions

CvReference

Image Processing
Structural Analysis
Motion Analysis and Object Tracking Reference
Pattern Recognition
Camera Calibration and 3D Reconstruction

CvAux

Stereo Correspondence Functions
View Morphing Functions
3D Tracking Functions
Eigen Objects (PCA) Functions
Embedded Hidden Markov Model Functions

HighGUI

Simple GUI
Loading and Saving Images
Video I/O functions
Utility and System Functions

Machine Learning

Introduction Common classes and functions
Normal Bayes Classifier
K Nearest Neighbors
Support Vector Machines
Decision Trees
Boosting
Random Trees
Expectation-Maximization
Neural Networks

We take a look into previous display image sample program.


#include <highgui.h>

int main (int argc, char** argv)
{
IplImage* img = cvLoadImage(argv[1]);
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Example1");

return 0;
}

Let’s go through line by line.
Line 1: header component inclusion.


#include <highgui.h>

We include highgui.h to provide access to HighGUI component. By including this header file, by default we also include cxcore.h; as you can see from beginning part of highgui.h content.


#ifndef _HIGH_GUI_
#define _HIGH_GUI_

#ifndef SKIP_INCLUDES

 #include "cxcore.h"
 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
 #include <windows.h>
 #endif

#else // SKIP_INCLUDES

...

Line 5: image loading.


IplImage* img = cvLoadImage(argv[1]);

Loading image use function under HighGUI.


IplImage* cvLoadImage(

const char* filename,
int iscolor=CV_LOAD_IMAGE_COLOR );

Input is a pointer to image file and optionally specific color type of the loaded image. cvLoadImage() can read a wide variety of image formats (bmp, dib, jpeg, jpe, png, pbm, pgm, ppm, sr, ras, and tiff). A pointer to an allocated image data structure is then returned. This structure, called IplImage, is the OpenCV construct with which you will deal the most. IplImage is defined in cxcore.h.

Line 6: create window.


cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);

Used to opens a window on the screen that can contain and display an image. Provided by the HighGUI library.


int cvNamedWindow(const char* name, int flags);

This function also assigns a name to the window (in this case, "Example1"). Future HighGUI calls that interacts with this window will refer to it by this name.
Second argument defines window properties.

Line 7: display image.


cvShowImage("Example1", img);

Whenever we have an image in the form of an IplImage* pointer, we can display it in an existing window with cvShowImage(). Provided by the HighGUI library.


void cvShowImage(const char* name, const CvArr* image);

The cvShowImage() function requires that a named window already exist (created by cvNamedWindow()).

Line 8: event wait key.


cvWaitKey(0);

Provided by HighGUI library, the cvWaitKey() function asks the program to stop and wait for a keystroke.


int cvWaitKey(int delay=0);

Input delay in millisecond; if value is 0 or negative, the program will wait indefinitely for a keypress. This function returns the code of the pressed key or -1 if no key was pressed.

Line 9: free up image.


cvReleaseImage(&img);

Once we are through with an image, we can free the allocated memory. Provided by cxcore.h.


void cvReleaseImage(IplImage** image);

OpenCV expects a pointer point to the IplImage* pointer, i.e. the loaded image pointer, so that we feed an address of img (an IplImage* pointer). After the call is completed, the pointer img will be set to NULL.

Line 10: destroy window.


cvDestroyWindow("Example1");

Finally, we can destroy the window itself.


void cvDestroyWindow(const char* name);

The function cvDestroy() will close the window and de-allocate any associated memory usage (including the window's internal image buffer, which is holding the copy of the pixel information from *img).

Reference:

  1. Bradski, G, and Kaehler, A. Learning OpenCV. O'Reilly, 2008.
  2. OpenCV documentation from OpenCV2.0\doc\opencv.pdf.

Post a Comment

Required fields are marked *
*
*