
This example demonstrates how to use frame filters to perform basic image processing.
It shows, how to:
The source code for the VB.NET and C# versions of this sample program can be found in the directories samples\VB71\Filter Inspector and samples\C#\Filter Inspector.
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.
[VB.NET]
If Not IcImagingControl1.DeviceValid Then IcImagingControl1.ShowDeviceSettingsDialog() If Not IcImagingControl1.DeviceValid Then Close() Return End If End If ' 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()
[C#]
if( !icImagingControl1.DeviceValid ) { icImagingControl1.ShowDeviceSettingsDialog(); if( !icImagingControl1.DeviceValid ) { 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();
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:
[VB.NET]
' 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. For Each ffi As TIS.Imaging.FrameFilterInfo In IcImagingControl1.FrameFilterInfos If modulePathCollection.IndexOf(ffi.ModulePath) < 0 Then lstFrameFilterModules.Items.Add(ffi.ModuleName) modulePathCollection.Add(ffi.ModulePath) End If Next
[C#]
// 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 icImagingControl1.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:
[VB.NET]
Private Sub lstFrameFilterModules_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstFrameFilterModules.SelectedIndexChanged ' Get the full path to the selected module from the ModulePaths collection. Dim selectedModulePath As String = modulePathCollection(lstFrameFilterModules.SelectedIndex) lstFrameFilters.Items.Clear() For Each ffi As TIS.Imaging.FrameFilterInfo In IcImagingControl1.FrameFilterInfos If ffi.ModulePath = selectedModulePath Then lstFrameFilters.Items.Add(ffi) End If Next End Sub
[C#]
private void lstFrameFilterModules_SelectedIndexChanged(object sender, System.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 icImagingControl1.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 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.
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:
[VB.NET]
' Get the selected FrameFilterInfo object Dim ffi As TIS.Imaging.FrameFilterInfo = CType(lstFrameFilters.SelectedItem, TIS.Imaging.FrameFilterInfo) If Not ffi Is Nothing Then ' Create the new FrameFilter instance. Dim newFrameFilter As TIS.Imaging.FrameFilter = IcImagingControl1.FrameFilterCreate(ffi)
[C#]
// 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 = icImagingControl1.FrameFilterCreate( ffi );
The frame filter instance is created by calling ICImagingControl.FrameFilterCreate with the FrameFilterInfo object as its parameter.
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.
[VB.NET]
' If live mode is active, stop. Dim wasLive As Boolean = IcImagingControl1.LiveVideoRunning If wasLive Then IcImagingControl1.LiveStop() End If ' Set the new frame filter. IcImagingControl1.DeviceFrameFilters.Clear() IcImagingControl1.DeviceFrameFilters.Add(newFrameFilter) ' If live mode was active, restart. If wasLive Then IcImagingControl1.LiveStart() End If
[C#]
// 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.