Completing the Form

The Form1_Load procedure is very similar to that in the previous example. First, initialize WiT Engine as usual. Map the display names ‘image’ and ‘display’ to the Windows handle of the Picture Box control. ‘display’ is the title of the display operator in the igraph. ‘image’ is an arbitrary name chosen to represent the binding between the Picture Box control and the frame grabber accessed by the LiveDisplay method. Finally, load the WIC to run the grab and image processing.

[C#]
    withandle = WiT.engine.Init4(this.Handle, 0, "-showStatus 0",
                    null, null, null);
    WiT.engine.SetDisplayWnd("image", outputDisp.Handle);
    WiT.engine.SetDisplayWnd("display", outputDisp.Handle);
    string wicName = Environment.GetEnvironmentVariable("WITHOME") +
        "\\demoPrograms\\engine\\wic\\fg";
    exehandle = WiT.engine.Load(wicName);

[Visual Basic]
    withandle = WiT.engine.Init4(Me.Handle, 0, "-showStatus 0", _
                        Nothing, Nothing, Nothing)
    WiT.engine.SetDisplayWnd("display", PictureBox1.Handle)
    WiT.engine.SetDisplayWnd("image", PictureBox1.Handle)
    Dim wicName As String = _
            Environment.GetEnvironmentVariable("WITHOME") + _
            "\\demoPrograms\\engine\\wic\\fg"
    exehandle = WiT.engine.Load(wicName)

The live_Click method uses the LiveDisplay method to toggle the display of live video. LiveDisplay causes WiT to continuously update the live video image in the background, but returns execution to the application immediately. It may also utilize hardware features from the frame grabber for high-speed live video display if possible.

[C#]
    liveMode = true;
    WiT.engine.LiveDisplay("image", null, 1);

[Visual Basic]
    liveMode = True
    WiT.engine.LiveDisplay("image", Nothing, 1)

The first argument to LiveDisplay specifies the window name to be used for displaying live video. In this example it must be set to ‘image’, because that is the name we chose in the call to SetDisplayWnd during the form load step. The second argument specifies the name of the frame grabber. A zero value passed uses the first frame grabber loaded by WiT. If you are using more than one frame grabber, then the name of the frame grabber as it appears in the WiT operator explorer must be used. The third argument turns live video on (1) or off (0).

The grab_Click method checks if live video is active. If it is, then it is stopped by passing the LiveDisplay method a zero (off) as the third argument. Then, it uses the ControlExec method to run the specified WIC. The WIC fg.wic grabs a single frame, inverts it, and then displays the result. Since the output of the display operator was mapped to the Picture Box control’s window, the image will appear in your .Net application window.

[C#]
    if (liveMode)
    {
        WiT.engine.LiveDisplay("image", null, 0);
        liveMode = false;
    }
    WiT.engine.ControlExec(exehandle,
        (short)WiT.ExeCmds.WIT_EXE_FLASH, 0);

[Visual Basic]
    If (liveMode) Then
       WiT.engine.LiveDisplay("image", Nothing, 0)
       liveMode = False
    End If
    WiT.engine.ControlExec(exehandle, _
        CType(WiT.ExeCmds.WIT_EXE_FLASH, Short), 0)

Previous 

Up 

Next