IC Imaging Control ActiveX

Filter Inspector

Filter Inspector

This example demonstrates how to use frame filters to perform basic image processing.

It shows, how to:

  • Enumerate the available frame filters.
  • Create frame filter instances.
  • Set a frame filter to do image processing on live video.

The source code for this sample program can be found in the samples\VB6\Filter Inspector directory.

Using the Example

On the left side of the dialog box, there are two list boxes. The upper list box shows all filter modules that were found by IC Imaging Control. When you select one of the filter modules in this list, the lower list box displays the frame filters that can be loaded from the selected module.

When you click on one of the frame filters in the second list box, the filter is inserted in the Device Path. The live video displayed on the right side of the dialog box should now visualize the work of the frame filter.

You can click the Dialog... button to display the selected filter's property dialog.

If you select a new filter, the old filter will be removed and the new one will be used instead.

To see the untransformed image data from the video capture device, click the Remove button.

Initialization

In the Form_Load event, ICImagingControl is initialized. If no device has been selected, ShowDeviceSettingsDialog is used to display a device selection dialog box. An important part here is to disable graphic overlay completely by setting ICImagingControl.OverlayBitmapPosition to PATHPOSITION_NONE, thus avoiding interference with the possible color formats of the frame filters.


If Not ICImagingControl1.DeviceValid Then
    ICImagingControl1.ShowDeviceSettingsDialog

    If Not ICImagingControl1.DeviceValid Then
        Unload Me
        Exit Sub
    End If
End If

' Disable all overlays, so that they do not influence the
' color format of the image stream.
ICImagingControl1.OverlayBitmapPosition = PATHPOSITION_NONE

' Start live mode.
ICImagingControl1.LiveStart

Enumerating Available Frame Filters

To obtain a list of available frame filters, use ICImagingControl.FrameFilterInfos, which returns a collection of FrameFilterInfo objects.

Now we want to fill a list box with the names of the files in which the filters have been found. To do that, we look at each filter and add its module name to the list box, while filling ModulePaths with the module paths of the filters. The module names are not added, if the module path is already in the collection:

' Use a collection to save the full paths to the filter modules.
Set ModulePaths = New Collection

' For each filter info:
' - Check if the filter's path is already in the module paths collection
' - If not, add the module name to the filter module list box.
Dim info As FrameFilterInfo
For Each info In ICImagingControl1.FrameFilterInfos

    Dim found As Boolean
    found = False

    Dim path As Variant
    For Each path In ModulePaths
        If path = info.ModulePath Then
            found = True
        End If
    Next path

    If Not found Then
        lstModules.AddItem info.ModuleName
        ModulePaths.Add info.ModulePath
    End If
Next info

In the event handler, which is called when the user selects a filter module name from the list box, a second list box is filled with the names of the filters in that module:

Private Sub lstModules_Click()

    lstFrameFilters.Clear

    ' Get the full path to the selected module from the ModulePaths collection.
    Dim selectedModulePath As String
    selectedModulePath = ModulePaths(lstModules.ListIndex + 1)

    ' For each available frame filter, check whether the module path
    ' equals the selelected module path.
    Dim i As Integer
    For i = 1 To ICImagingControl1.FrameFilterInfos.Count

        If ICImagingControl1.FrameFilterInfos(i).ModulePath = selectedModulePath Then
            lstFrameFilters.AddItem ICImagingControl1.FrameFilterInfos(i).Name

            ' Save the index in the list box item data
            lstFrameFilters.ItemData(lstFrameFilters.ListCount - 1) = i
        End If

    Next i

End Sub

The loop fills a list box with all the frame filters that were loaded from the specified module. The index of the added filters in the original filter list (that was retrieved from ICImagingControl.FrameFilterInfos ) are stored in the list box's item data by setting ListBox.ItemData, thus allowing the filter info to be found when an end user clicks the item.

Creating Frame Filter Instances

When the user selects a filter from the filter list, the item data of the selected item is read, using ListBox.ItemData. Because we previously stored the filter's index in the list of available filters in the item data, we can use this number now to select the FrameFilterInfo in ICImagingControl.FrameFilterInfos:

' Retrieve the index from the list box item data.
Dim selectedFilterIndex As Integer
selectedFilterIndex = lstFrameFilters.ItemData(lstFrameFilters.ListIndex)

' Use the index to get the FrameFilterinfo.
Dim selectedFilterInfo As FrameFilterInfo
Set selectedFilterInfo = ICImagingControl1.FrameFilterInfos(selectedFilterIndex)

' Create the new FrameFilter instance.
Dim newFrameFilter As FrameFilter
Set newFrameFilter = ICImagingControl1.FrameFilterCreate(selectedFilterInfo)

The frame filter instance is created by calling ICImagingControl.FrameFilterCreate with the FrameFilterInfo object as its parameter.

Set the Frame Filter

To activate the frame filter, it has to be registered at the ICImagingControl object. The ICImagingControl.DeviceFrameFilters collection is cleared and the new filter is inserted. Device frame filters are used to transform the image data that comes from the video capture device.

' If live mode is active, stop.
Dim wasLive As Boolean
wasLive = ICImagingControl1.LiveVideoRunning
If wasLive Then ICImagingControl1.LiveStop

' Set the new frame filter.
ICImagingControl1.DeviceFrameFilters.Clear
ICImagingControl1.DeviceFrameFilters.Add newFrameFilter

' If live mode was active, restart.
If wasLive And ICImagingControl1.DeviceValid Then ICImagingControl1.LiveStart

Live mode has to be stopped in order to set a frame filter.

<< Programmer's Guide

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us