In This Tutorial We will Learn How to Use One of the Basic functionalities offered by the EmguCV Wrapper Namely the ImageBox Functionality In your Microsoft Visual Basic 2008 Express Edition. We Do this by Adding ImageBox functionality to your Toolbox and adding the ImageBox to your Windows Form and Displaying Images in the ImageBox by some very Basic Coding.
I assume that you have Downloaded and Installed EmguCV on ur system.
If it has installed corectly you will be having a folder named 'Emgu' in your "C:/Program Files " directory.
1) Open Your Microsoft Visual Basic 2008 Express Edition.
2) Create A New Project by Choosing from File Menu.
3) Choose "Windows Forms Application" and Give an appropriate Name for ur Project.
4) A Windows Form will open Automatically on the main Window of the Project Area.
5) Now Before Doing anything, You should add certain Dll files provided by EmguCV as references to your project.Make Sure that the following Files are on your local Drive at the following addresses.
6) The name of these Dll files are 'Emgu.CV.Dll', 'Emgu.CV.UI.Dll', 'Emgu.Util.dll'. They can be found at the following Local Addresses if u have installed the EmguCV properly:
Emgu.CV.Dll------------ C:\Program Files\Emgu\Emgu CV\Emgu.CV\obj\Debug
Emgu.CV.UI.Dll------- C:\Program Files\Emgu\Emgu CV\Emgu.CV.UI\obj\Debug
Emgu.Util.Dll--------- C:\Program Files\Emgu\Emgu CV\Emgu.Util\obj\Debug
7) Now Come Back to your Project. On the Upper Right Hand Side Corner You will find 'Solution Explorer' Window Pane in that window pane you will find the common files in your project 'CLICK' the 'Show All Files' button above to find all the files attached to your project. In these files you will also find a category called 'References' Right Click on it and Choose 'Add Reference' a dialog box opens choose Browse Tab and Go to the Locations Mentioned in the above Step and add each Dll file in turn.When you have completed successfully you will see that the Files have been added Under the 'References' Category.
8) Copy the Files 'Emgu.CV.UI.Dll' and 'Emgu.Util.Dll' to the folder containing Emgu.Cv.Dll file ie., (C:\Program Files\Emgu\Emgu CV\Emgu.CV\obj\Debug) Folder.
9)Open your form in designer view. From Toolbox, right click in the empty space of 'General' column. This should pop up a selection menu, where 'Choose Items' selection is available.
10)Click on 'Choose Items', you will see a 'Choose Toolbox Item' Dialog, from where click the 'Browse..' button on the lower right corner of the dialog.
11) Select 'Emgu.CV.UI.dll' file from 'Open' dialog, click the 'Open' button.
12) Now you should notice the ImageBox control has been added to the 'Choose Toolbox Items' dialog. Click 'Ok'.
13) The ImageBox will be available from the 'General' column in the Toolbox area. Pull the control and drag it on to your Windows form.
14) In the Same way Drag a TextBox, BuTTON and OpenFileDialog Controls on to your Form.
15)Double Click on the Button to Open Code View Window and paste the Following Code:
16) Paste The following at the very beginning of the file ie., above the Public Class Form1
Code: Select all
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.ShowDialog() TextBox1.Text = OpenFileDialog1.FileName Dim img1 As New Image(Of Bgr, [Byte])(Image.FromFile(TextBox1.Text)) ImageBox1.Image = img1 End Sub
17) Click Save All and save the project.Run the Project to see the results.
Code: Select all
Imports System Imports System.Windows.Forms Imports System.Drawing Imports Emgu.CV Imports Emgu.Util Imports Emgu.CV.Structure Imports Emgu.CV.CvEnum Imports Emgu.CV.UI
The Whole Source Code is AS Follows:
Code: Select all
Imports System Imports System.Windows.Forms Imports System.Drawing Imports Emgu.CV Imports Emgu.CV.UI Imports Emgu.Util Imports Emgu.CV.Structure Imports Emgu.CV.CvEnum Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.ShowDialog() TextBox1.Text = OpenFileDialog1.FileName Dim img1 As New Image(Of Bgr, [Byte])(Image.FromFile(TextBox1.Text)) ImageBox1.Image = img1 End Sub End Class
That's All For now Folks, In the next Tutorial we will modify the above Windows application to detect faces in image files.