Filter Inspector

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

It shows, how to:

The source code for this sample program can be found under samples\C# *\Filter Inspector in your My Documents/IC Imaging Control 3.5 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.


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 PathPositions.None thus avoiding interference with the possible color formats of the frame filters.

if( !icImagingControl1.LoadShowSaveDeviceState("lastSelectedDeviceState.xml") ) { MessageBox.Show("No device was selected.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } // Disable all overlays, so that they do not influence the // color format of the image stream. icImagingControl1.OverlayBitmapPosition = TIS.Imaging.PathPositions.None; // Start live mode. icImagingControl1.LiveStart();

Enumerating Available Frame Filters

To obtain a list of available frame filters, use FrameFilterInfo.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. modulePathCollection = new System.Collections.Specialized.StringCollection(); // 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. foreach (TIS.Imaging.FrameFilterInfo ffi in TIS.Imaging.FrameFilterInfo.FrameFilterInfos) { if (modulePathCollection.IndexOf(ffi.ModulePath) < 0) { lstFrameFilterModules.Items.Add(ffi.ModuleName); modulePathCollection.Add(ffi.ModulePath); } }

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 void lstFrameFilterModules_SelectedIndexChanged(object sender, EventArgs e) { // Get the full path to the selected module from the ModulePaths collection. string selectedModulePath = modulePathCollection[lstFrameFilterModules.SelectedIndex]; lstFrameFilters.Items.Clear(); foreach (TIS.Imaging.FrameFilterInfo ffi in TIS.Imaging.FrameFilterInfo.FrameFilterInfos) { if (ffi.ModulePath == selectedModulePath) { lstFrameFilters.Items.Add(ffi); } } }

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 FrameFilterInfo.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:

// Get the selected FrameFilterInfo object TIS.Imaging.FrameFilterInfo ffi = (TIS.Imaging.FrameFilterInfo)lstFrameFilters.SelectedItem; if (ffi != null) { // Create the new FrameFilter instance. TIS.Imaging.FrameFilter newFrameFilter = TIS.Imaging.FrameFilter.Create(ffi);

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. bool wasLive = icImagingControl1.LiveVideoRunning; if (wasLive) { icImagingControl1.LiveStop(); } // Set the new frame filter. icImagingControl1.DeviceFrameFilters.Clear(); icImagingControl1.DeviceFrameFilters.Add(newFrameFilter); // If live mode was active, restart. if (wasLive) { icImagingControl1.LiveStart(); }

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

<< Programmer's Guide