-1

I built an project in C# with winform GUI on the .net framework. The aim of the program is to get data (image frames) from a frame grabber card and saving the data after doing some pre-processing on it.

The plugged camera is quite fast and has a pixel size of 640x480 with 16 Bit for each pixel and is working at 350 frames per second.

I added the library from the manufacturer that rises an event for every incoming frame and transfers the data as one-dimensional int16 array.

What I want to do is to average the bunch of frames for every second and saving the result in binary as an float array. Look here:

void Camera_OnRawImage(object sender, short[] data)
{
     float[] frame = Array.ConvertAll(data, x => (float)x);

     this.AverageProcess.AddImage(frame);
}

My problem is that there is a lot of data coming into my application. So the program is not able to process and save all the data before the next frames are pending to rise an event.

I already tried different approaches like:

  • multiple threads to parallel calculate the arrays

  • using marshalling methods for a better array access

  • converting the arrays to MathNET arrays and using the INTEL MKL on MathNET library to speed up the process. look here:

    internal void AddImage(float[] image) { currentFrameOfMeasurement++;

    Vector<float> newImage = Vector<float>.Build.DenseOfArray(image);
    newImage = newImage.Multiply(preAverageFactor);
    
    var row = FrameMat.Column(currentFrameOfPeriod).Add(newImage);
    
    FrameMat.SetColumn(currentFrameOfPeriod, row);
    
    currentFrameOfPeriod++;
    
    if (currentFrameOfPeriod >= this.Settings.FramesPerPeriod)
    {
         currentFrameOfPeriod = 0;
         currentPeriodCount++;
    }
    

    }

But that is also a little bit to slow. The RAM is increasing while grabbing the data. My methods need more than 10ms - which is quite to slow. To process and save the data must be possible. There is an application from the manufacturer which is doing a lot of processing on the grabbed data. It seems like the program is written in delphi. Maybe they are using better library for doing all these operations.

My question is now. Does anybody has an suggestion what I can do to speed up the processing and calculation of these arrays.

Thank you in advance

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
REMberry
  • 172
  • 1
  • 2
  • 12
  • Can you push the data into a `BlockingCollection` and consume it from there (in a different thread)? _Your consumer may be able to write it to a memory mapped file perhaps?_ – mjwills Dec 03 '17 at 12:03

1 Answers1

0

Use the Synchronized Queue (here) feature and queue in all the frames that come into your program and write a thread which can process the items in queue.