Getting started in VB.NET
Top  Previous  Next

This chapter shows you how to get started with ActiveGige control in VB.NET. With just a few mouse clicks and a few lines of code, you will be able to display a live video image in your VB.NET program, access the array of pixel values and display them in a table in real time.
.
Creating the Project

In the .NET development environment select New -> Project. The New Project Dialog box will appear. Select Visual Basic projects on the left and Windows Application on the right. In the Name filed below type the name of your application, for instance MyActiveGige and click OK . The project will be created, and the main application form will be displayed for editing.

Creating the Control

In the Toolbox select Components. From the Tools menu select Choose Items... -> COM Components and then select ActiveGige Class from the list. You will see ActiveGige icon appear at the bottom of the toolbox.

clip0066

Click the ActiveGige icon in the Toolbox and draw a rectangular area on the form. A rectangle with the text "ActiveGige Control" will appear on the form, and the Properties window on the right will display ActiveGige's properties.

Selecting the Camera

In the properties window, click the Camera property. The list box will display all GigE Vision™ compatible cameras connected to your system. Select the one you intend to use:

clip0068


Selecting the Pixel Format

In the Properties window, click the Format property. The list box will display all pixel formats available for the chosen camera. Select the one you intend to use:

clip0069


Adding the Start and Stop buttons

In the Toolbox select Windows Form , click on the Button icon and then draw a rectangular area on the program dialog. A button "Button1" will appear. Go to the Property window and change the Text property to "Start". Double click on the button. A new function Button1_Click will be added to the Form1.vb source code. Insert one line to the function body:

Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AxActiveGige1.Acquire = True
End
Sub

Repeat the same procedure for the Stop button adding the following line to the Button2_Click function:

Private
Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AxActiveGige1.Acquire = False
End
Sub

Adding the Grid

From the Tools menu select Customize Toolbox and then select Microsoft Flex Grid Control from the list. A FlexGrid icon will appear at the bottom of the toolbox. Click the icon and draw a rectangular area on the form. Go to the Property window and set both Cols and Rows property to 5. You will see a corresponding number of rows and columns added to the grid on the main form.

Your final design of the main form will be similar to this:


clip0065


Adding the FrameAcquired event

Double-click in the ActiveGige control window. The code window will appear with an empty AxActiveGige1_FrameAcquired subroutine in it. It is now time to enter the code that will retrieve an image data array and display pixel values in the grid cells:

Private
Sub AxActiveGige1_FrameAcquired(ByVal sender As System.Object, ByVal e As AxACTIVEGIGELib._IActiveGigeEvents_FrameAcquiredEvent) Handles AxActiveGige1.FrameAcquired
Dim
A As Array
Dim
X As Integer
Dim Y As Integer
A = AxActiveGige1.GetImageData
For
y = 1 To 4
For
x = 1 To 4
AxMSFlexGrid1.set_TextMatrix(Y, X, A(X, Y))
Next
Next
End Sub


Running the application

Close the design window. From the Debug menu of the development environment select Start or press F5. This will build and run the application. The application dialog will appear on the screen with a black image window and empty text boxes. Click the Start button to activate the continuous video acquisition. The live image will appear in the control window and the real-time pixel values will be displayed in the table.

Note - make sure to close the form containing ActiveGige control before running your application, or otherwise the IDE will maintain the exclusive control over the camera and will not allow your application to display the video.