I have a Genicam camera capturing Mono16 images 366X640 pixels.
I am trying to build a simple class/program using the 3rd Generation Stack that continuously grabs images and copies the image’s raw data into a buffer (byte array).
After that, I invoke the “New Image” event and the class subscribes processing it outside the Common Vision Blox environment.
The FPS I am working with is 230. (image every 4.3 ms).
The outside processing of every image takes ~2ms.
- Is RegisterManagedFlowSetPool needed in that case?
- Am I using the right way to copy the raw data into an array?
image.Planes[0].TryGetLinearAccess(out LinearAccessData imageData);
Marshal.Copy(imageData.BasePtr, _imageBuffers[index], 0, bufferSize);```
- Is running the grabbing function on a thread in a specific core or setting a processor affinity for better performance helpful/recommended?
private void RunImageGrabbing(CancellationToken token)
{
double fps = 0;
int index = 0;
using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))
{
using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.GenTL) as GenICamDevice)
{
var stream = device.GetStream<ImageStream>(0);
stream.RegisterManagedFlowSetPool(100);
#region Initialize Buffer
int bufferSize = GetImageSize(device);
_imageBuffers = new byte[NumberOfBuffers][];
for (int i = 0; i < NumberOfBuffers; i++)
_imageBuffers[i] = new byte[bufferSize];
#endregion
stream.Start();
Cvb.Utilities.TWStartStopWatch(m_Timer, 0);
while (grabbing && !token.IsCancellationRequested)
{
using (var image = stream.Wait(token, out WaitStatus status))
{
if (status == WaitStatus.Ok && image != null)
{
image.Planes[0].TryGetLinearAccess(out LinearAccessData imageData);
Marshal.Copy(imageData.BasePtr, _imageBuffers[index], 0, bufferSize);
index = (index + 1) % NumberOfBuffers;
// Calculate Current FPS
double dTimeMS;
Cvb.Utilities.TWReadStopWatch(m_Timer, 0, out dTimeMS);
fps = (1.0 / dTimeMS * 1000.0);
Console.WriteLine($"FPS {fps}");
Cvb.Utilities.TWStartStopWatch(m_Timer, 0);
//Event
OnNewImage?.Invoke(fps, _imageBuffers[index]);
}
}
}
stream.Abort();
}
}
}