Hello World in CSharp
Jump to navigation
Jump to search
We will start by the Hello World sample, written in C#
using Emgu.CV;
using Emgu.CV.CvEnum;
...
String win1 = "Test Window"; //The name of the window
CvInvoke.cvNamedWindow(win1); //Create the window using the specific name
Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0)); //Create an image of 400x200 of Blue color
MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0); //Create the font
img.Draw("Hello, world", ref f, new Point2D<int>(10, 80), new Bgr(0, 255, 0)); //Draw "Hello, world." on the image using the specific font
CvInvoke.cvShowImage(win1, img); //Show the image
CvInvoke.cvWaitKey(0); //Wait for the key pressing event
CvInvoke.cvDestroyWindow(win1); //Destory the window
The above code will create an image of 400x200 with blue background color and the String "Hello, world" in green on the foreground. The image will be displayed a window named "Test Window".