Now let’s begin to design our first form. It’s very simple because this is our first project. We just put a button in the middle of our form. We want a “Hello World” window to pop up when we click on this button, as shown in the following screenshot:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
namespace helloworld
{
public partial class Form1 : Form
{
String winname = "First Window";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender,EventArgs e)
{
//create a window with a specific name
CvInvoke.cvNamedWindow(winname);
//create a image of 480x200 with color yellow
using (Image<Bgr, byte> imag1 = new Image<Bgr, byte>(480, 200,new Bgr(0,255,255))){
//create a font
MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX,1.0,1.0);
//draw "hello,world" on the yellow image;start point is (25,100) with color blue
imag1.Draw("hello, world", ref font, new Point(25,100), new Bgr(255, 0, 0));
CvInvoke.cvShowImage(winname,imag1.Ptr);
CvInvoke.cvWaitKey(0);
CvInvoke.cvDestroyWindow(winname);
}
}
}
}