Wrapping OpenCV

Shin Shi

November 2013

(For more resources related to this topic, see here.)

Architecture overview

In this section we will examine and compare the architectures of OpenCV and Emgu CV.


In the hello-world project, we already knew our code had something to do with the bin folder in the Emgu library that we installed. Those files are OpenCV DLLs, which have the filename starting with opencv_. So the Emgu CV users need to have some basic knowledge about OpenCV.

OpenCV is broadly structured into five main components. Four of them are described in the following section:

  • The first one is the CV component, which includes the algorithms about computer vision and basic image processing. All the methods for basic processes are found here.
  • ML is short for Machine Learning, which contains popular machine learning algorithms with clustering tools and statistical classifiers.

  • HighGUI is designed to construct user-friendly interfaces to load and store media data.
  • CXCore is the most important one. This component provides all the basic data structures and contents.

The components can be seen in the following diagram:

The preceding structure map does not include CvAux, which contains many areas. It can be divided into two parts: defunct areas and experimental algorithms. CvAux is not particularly well documented in the Wiki, but it covers many features. Some of them may migrate to CV in the future, others probably never will.

Emgu CV

Emgu CV can be seen as two layers on top of OpenCV, which are explained as follows:

  • Layer 1 is the basic layer. It includes enumeration, structure, and function mappings. The namespaces are direct wrappers from OpenCV components.
  • Layer 2 is an upper layer. It takes good advantage of .NET framework and mixes the classes together. It can be seen in the bridge from OpenCV to .NET.

The architecture of Emgu CV can be seen in the following diagram, which includes more details:

After we create our new Emgu CV project, the first thing we will do is add references. Now we can see what those DLLs are used for:

  • Emgu.Util.dll: A collection of .NET utilities
  • Emgu.CV.dll: Basic image-processing algorithms from OpenCV
  • Emgu.CV.UI.dll: Useful tools for Emgu controls
  • Emgu.CV.GPU.dll: GPU processing (Nvidia Cuda)
  • Emgu.CV.ML.dll: Machine learning algorithms

Function mapping

Emgu.CV.Invoke class introduces an easy way to directly call OpenCV functions in .NET programming languages. Every method in the Emgu.CV.Invoke class keeps the original name in OpenCV. An example of cvCreateImage is given here. In Emgu CV, we write it like this:

IntPtr img1 = CvInvoke.cvCreateImage(new Size(256, 256), IPL_DEPTH.IPL_DEPTH_16U, 1);

It shows the same effects in OpenCV code:

IplImage* img1 = cvCreateImage(cvSize(256, 256), IPL_DEPTH_16U, 1);

Both of them will create an image with the size of 256 x 256 pixels, the depth of 16 bit unsigned, and the channel 1.

According to Emgu CV library documentation, the CvInvoke type exposes the many members and methods. All those hundreds of methods are very useful because they are base functions. Please see the Emgu CV library documentation for more details.

Structure mapping

Emgu.CV.Structurenamespace contains all the direct mappings to OpenCV basic structures. Examples are shown in the following table:

Emgu CV structure

OpenCV structure









The prefix M in the table means managed structure.

The best thing is that Emgu CV mixes .NET graphics and the OpenCV structures together. Parts of them are shown in the following structure:

.NET structure

OpenCV structure









This is amazing because it is just like a bridge from OpenCV to .NET structure. If we know something about .NET graphics programming, we can code our Emgu project more easily because of the structure mapping.

Enumeration mapping

Emgu.CV.CvEnum namespace contains all the direct mappings to OpenCV enumerations. An example is given here:


This enumeration shares the same value in OpenCV given here:


Both of them are 16. We can see that each Emgu CV and OpenCV enum type has the same name. That is what direct mapping means. OpenCV programmers will get quick access to Emgu CV because of it. Please see the Emgu CV library documentation for more details.


In this article, we examined and compared the architectures of OpenCV and Emgu CV. By the end of the article, the user has a preliminary knowledge of Emgu CV.

Resources for Article:

Further resources on this subject:

You've been reading an excerpt of:

Emgu CV Essentials

Explore Title