MATLAB: How to calculate the packet delay for a GigE Vision camera to prevent dropped frames

droppedframesgigeImage Acquisition Toolboxpacketdelaypackets

I am using a GigE Vision compliant camera with the Image Acquisition Toolbox GigE Vision adaptor. However, after a number of frames are acquired the acquisition stops and the following error message is displayed:
 
gige: Block/frame 23 is being dropped because a lost packet is unable to be resent.There are several possible causes for packets being lost. See the troubleshooting information in the "Configuring GigE Vision Devices" section of the Image Acquisition Toolbox documentation.
 
How can I calculate the recommended packet delay corresponding to my camera settings?

Best Answer

Note: Before configuring the camera GigE streaming parameters in MATLAB, make sure the Gigabit Ethernet card/adapter configuration and network connection settings are according to the "GigE Vision Quick Start Configuration Guide" (attached at the end of this article as GigEVisionQuickStart.pdf).
The following documentation pages contain additional configuration and troubleshooting information:
The dropped frame error message can be caused by GigE packets being lost as a result of high CPU load.
To lower the CPU load when acquiring images with the GigE adaptor try the following:
1. Raise the value of the PacketSize source property while making sure it is not larger than the Ethernet card jumbo frame/packet size.
Note: With some hardware configurations the dropped frame error might be encountered when the PacketSize is equal to the Ethernet card jumbo frame size, so try using smaller PacketSize values (for example, if the Ethernet card Jumbo frame is 9000 bytes, try setting the PacketSize to 8000).
2. For optimum performance and to prevent dropped frames configure the camera to insert an appropriate delay between packets by setting the PacketDelay source property.
 
Note:
  • The PacketDelay property is available for Image Acquisition Toolbox 4.2 (R2011b) and above
  • Starting in MATLAB R2013a the toolbox does an automatic configuration of the PacketSize value. This should lead to increased performance and lower CPU load. Due to this optimization of PacketSize, you may need to adjust your PacketDelay accordingly.
The recommended PacketDelay value depends on the PacketSize, camera resolution (image height and width), pixel format (for example 'Mono8'), camera frame rate, and other camera specific settings.
The attached CalculatePacketDelay.m and CalculateFrameRate.m scripts can be used to calculate the recommended PacketDelay value.
The 'CalculatePacketDelay.m' script will calculate the recommended packet delay corresponding to the frame rate the camera is set to operate at and it takes as input arguments the video input object and the camera frame rate.
 
CalculatePacketDelay(vid, framesPerSecond)
Depending on the camera model, the camera frame rate may be obtained as a device specific property, but it can also be estimated (or verified) with the 'CalculateFrameRate.m' script, which acquires a specified number of frames to determine an effective frame rate.
 
CalculateFrameRate(vid, framesToAcquire)
Example:
 
>> vid = videoinput('gige', 1, 'Mono8');
>> src = getselectedsource(vid);
>> src.PacketSize = 9014;
>> framesToAcquire = 5;
>> framesPerSecond = CalculateFrameRate(vid, framesToAcquire)
ans =
10.0003
>> delay = CalculatePacketDelay(vid, framesPerSecond)
Calculating Packet Delay for:
FrameRate = 10, PacketSize = 9014, FrameHeight = 656, FrameWidth = 490, VideoFormat = Mono8
Time stamp tick frequency (ticks/s): 31250000.0
Used gigabit bandwitdh: 2.6 %
Packet Delay: 72097.8 (ticks)
delay =
7.2098e+04
>> src.PacketDelay = delay;
Note: To prevent acquisition stopping due to a dropped frame error, use the PacketDelay value recommended for your camera configuration parameters. Using values arbitrarily larger or smaller is not likely to provide a correct configuration for the GigE streaming process.