First, we will introduce EmguCV.
EmguCV a is an encapsulation of the OpenCV image processing library on the. NET platform. That is, the. NET version of OpenCV. It runs in. NET compatible programming languages and calls OpenCV functions, such as C #, VB, VC ++, and IronPython. This encapsulation library can be compiled under Mono and run on Linux/Mac OS X.
Next, we will briefly introduce how to install EmguCV:
1. First, ensure that your computer has installed openCV and that the environment variables have been set. For more information, see the official OpenCV Chinese website.
2. Download The EmguCV compressed package, which is actually a dll library that can reference OpenCV functions in Visual Studio2005/2008. My next is version 1.50, which includes emgu.cv.windows.binary-1.5.0.0.zip ". Decompress the package and copy its DLL to the Bin folder under the OpenCV installation directory.
3. Create a c # form application and add "Emgu. CV. dll "," Emgu. util. dll and other DLL references, and some Form Controls, mainly including Emgu. CV. UI. when dll is added to the toolbox, ImageBox and HistogramCtrl are displayed.
4. Then, add using Emgu. CV; using Emgu. Util at the beginning of the program. After namespace, all the database functions of EmguCV can be used.
Next, let's talk about the basic problems of using EmguCV and what we should pay attention:
1. When using OpenCv and EmguCv in. net, the conversion must be performed between the supported image formats .. Net uses Bitmap class to carry images, OpenCv uses IplImage pointer to carry images, and EmguCv uses Image <TColor, TDepth> to carry images.
There are several ways to read images. In OpenCV, you can use:
IntPtr srcImage; // IntPtr instead of IplImage *
SrcImage = CvInvoke. cvLoadImage ("lena.jpg", Emgu. CV. CvEnum. IPL_DEPTH.IPL_DEPTH_8U, 1 );
In EmguCV, we recommend that you use the Image class for read operations.
// Read a bgr image and put lena.jpg In the DEBUG directory.
Image <Bgr, byte> img = new Image <Bgr, byte> ("lena.jpg ");
// ToBitmap () converts IImage format to Bitmap format, which can be used for PictureBox.
PictureBox1.Image = img. ToBitmap (); or pictureBox1.Image = img. Bitmap;
The Image format can also be converted to IntPtr, for example:
SrcImage = img. Ptr;
The Image class is powerful, and it encapsulates many common Image processing functions.
2. Image Data Processing
You can use the OpenCV pointer access method in c ++, but in the c #. net environment, it is insecure code and the unsafe keyword must be added.
Unsafe
{
(Byte *) img. MIplImage. imageData + img. MIplImage. widthStep * I) [j] = 0;
}
We recommend that you use EmguCV.
// Read and write data to column x of row y of Image <Bgr, byte>.
Bgr color = img [y, x];
Img [y, x] = color;
Bgr data can be accessed through Bgr. Blue, Bgr. Green, Bgr. Red, and Gray data can be accessed through Gray. intensity. All data can be read and written.
3. judge whether a video has read the end Of the file. Do not use null. Use an empty IntPtr, that is, IntPtr eof = new IntPtr (), to check whether it is equal to eof.
4. IplImage *, CvCapture * and other pointers are replaced by IntPtr in C #, and there is no cvGetMCvSize function, so cvGetImageROI is used for the moment.
5. Because no address symbol is obtained in C #, all the addresses here are replaced by references, that is, ref.
6. All predefined constants in OpenCV are encapsulated in the enumeration type Emgu. CV. CvEnum.
Refer:
1. http://www.cnblogs.com/xrwang/archive/2010/01/26/TheInteractionOfOpenCv-EmguCvANDDotNet.html
2. http://hi.baidu.com/pengjun/blog/item/4ce4cb80213c3ddf9123d9c3.html
3. http://www.dotblogs.com.tw/chou/archive/2009/06/13/8812.aspx
4. http://hi.baidu.com/barty/blog/item/0bc7353eac40393671cf6c42.html