Image Acquisition: Getting Droped Frames

Short source code snippet that illustrates how to get droped frames using IC Imaging Control ImageAvailable Event.
Language:.NET C#/Visual Basic
Version:3.0.3
Released on:April 7, 2005
Author:IC Imaging Control Support Department
Requirements:IC Imaging Control >32.1
Camera, converter or grabber with WDM Stream Class drivers.

On time expensive ImageProcessing in ImageAvailable, framedrops occurs. For this purpose, Ic Imaging Control provides getting droped frames, to prevent loosing these frames.

To recieve the droped frames it is necessary to set .OverlayUpdateEvent Enable to false. Also .LiveCaptureContinuous must set to True and .LiveDisplay to False, for using the ImageAvailable Event to display image data. Of course, the .ImageRingBufferSize must set big enough to store the droped frames. In this sample an ImageRingBuffer with a size of 30 is used.

[C#]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    IcImagingControl1.ShowDeviceSettingsDialog()

    If IcImagingControl1.DeviceValid Then

        IcImagingControl1.LiveDisplayDefault = False
        IcImagingControl1.LiveDisplayHeight = IcImagingControl1.Height
        IcImagingControl1.LiveDisplayWidth = IcImagingControl1.Width

        IcImagingControl1.LiveCaptureContinuous = True
        IcImagingControl1.LiveCaptureLastImage = False
        IcImagingControl1.LiveDisplay = False

        ' To recieve dropped frames it is necessary to set
        ' OverlayUpdateEventEnable to false.
        IcImagingControl1.OverlayUpdateEventEnable = False

        ' Set the imagebuffer (must be large enough).
        IcImagingControl1.ImageRingBufferSize = 30

        IcImagingControl1.LiveStart()

    End If

End Sub

Now , its possible to recieve framedrops in ImageAvailable, as follows:

[C#]
Private Sub IcImagingControl1_ImageAvailable_1(ByVal sender As System.Object, ByVal e As TIS.Imaging.ICImagingControl.ImageAvailableEventArgs) Handles IcImagingControl1.ImageAvailable

    Dim buffer As TIS.Imaging.ImageBuffer = IcImagingControl1.ImageBuffers(e.bufferIndex)

    ' Calculate the difference between the last processed buffer index and the current buffer
    ' index. This will return the count of dropped frames.
    Dim DroppedFramesCount As Integer = e.bufferIndex - LastHandledFrameIndex

    ' If DroppedFramesCount is less than zero then the ring buffer index has been started
    ' again at zero between the LastHandledFrameIndex and then current e.bufferIndex.
    If DroppedFramesCount < 0 Then
        DroppedFramesCount = IcImagingControl1.ImageRingBufferSize + DroppedFramesCount
    End If

    ' If frames have been dropped, then display all non processed frames in the following
    ' loop.
    While (DroppedFramesCount > 1)

        'Get all droped frames
        Dim DroppedFrameIndex As Integer = LastHandledFrameIndex - (DroppedFramesCount - 1)

        If (DroppedFrameIndex < 0) Then

            'Keep in mind DroppedFrameIndex is negative!
            DroppedFrameIndex = IcImagingControl1.ImageRingBufferSize + DroppedFrameIndex

        End If

        ' Get the dropped frame.
        Dim LostFrame As TIS.Imaging.ImageBuffer
        LostFrame = IcImagingControl1.ImageBuffers(DroppedFrameIndex)

        ' Display the dropped frame.
        IcImagingControl1.DisplayImageBuffer(LostFrame)

        DroppedFramesCount = DroppedFramesCount - 1

    End While

    ' Sleep for simulate time expensive image processing.
    System.Threading.Thread.Sleep(300)

    IcImagingControl1.DisplayImageBuffer(buffer)

    ' Save the ring buffer index of the current frame into LastHandledFrameIndex. This will
    ' be used next time ImageAvailable is called again.
    LastHandledFrameIndex = e.bufferIndex

End Sub

The bufferindex of the actual frame is compared with the bufferindex of the last frame. If the Difference is greater than 1, framedrops are occured. The droped frames are recieved by the accordant index of the ImageRingBuffer using .ImageBuffers(bufferindex - (dif - 1)).

Related Source Code Samples

Disclaimer
The source code that appears in the IC Imaging Control Source Code Library is indented for educational purposes only. The Imaging Source Europe GmbH, the manufacturer of IC Imaging Control, does not assume any kind of warranty expressed or implied, resulting from the use of the content of this page.

This site is part of The Imaging Source Network. Other sites include Company Portal, Image Processing, Astronomy Cameras, Astronomy Cameras Blog, Blog caméras d'astronomie, Astronomy Cameras Competition, TX Text Control, LiveDocx, phpLiveDocx and Forums.