Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void UpdateFrame()
- {
- frameView.DisplayNewFrame(acquisition.frameDataShorts,
- mfvm.cameras[openCamIndex].sensorWidth,
- mfvm.cameras[openCamIndex].sensorHeight,
- mfvm.cameras[openCamIndex].bitDepth,
- acquisition.stream_size, false);
- frameView.fvvm.frameNumApp = (UInt16)acquisition.frameInfoLatest.FrameNr;
- List<Tuple<UInt16, UInt16, UInt64>> taskResults =
- new List<Tuple<UInt16, UInt16, UInt64>>();
- Tuple<UInt16, UInt16, UInt64> result = null;
- // Count cores
- int coreCount = 4;
- // Calculating segment size
- int bufferSegmentSize = acquisition.frameDataShorts.Length / coreCount;
- // Creating Tasks
- Task[] tasks = new Task[coreCount];
- Object myLock = new Object();
- Stopwatch sw = Stopwatch.StartNew();
- for (int i = 0; i < tasks.Length; i++)
- {
- int j = i;
- tasks[j] = Task.Factory.StartNew(
- () =>
- {
- lock (myLock)
- {
- taskResults.Add(GetSubFrameStats(j * bufferSegmentSize,
- (j + 1) * bufferSegmentSize));
- }
- });
- }
- Task.WaitAll(tasks);
- result = CompareSubFrameStats(taskResults);
- sw.Stop();
- frameView.fvvm.frameMin = result.Item1;
- frameView.fvvm.frameMax = result.Item2;
- frameView.fvvm.frameMean = (UInt16)(result.Item3 /
- (UInt64)acquisition.frameDataShorts.Length);
- }
- private Tuple<UInt16, UInt16, UInt64> CompareSubFrameStats(
- List<Tuple<UInt16, UInt16, UInt64>> stats)
- {
- UInt16 tempMin = (UInt16)(Math.Pow(2, mfvm.cameras[openCamIndex].bitDepth) - 1);
- UInt16 tempMax = 0;
- UInt64 tempSum = 0;
- for (int i = 0; i < stats.Count; i++)
- {
- if (stats[i].Item1 < tempMin)
- tempMin = stats[i].Item1;
- if (stats[i].Item2 > tempMax)
- tempMax = stats[i].Item2;
- tempSum += stats[i].Item3;
- }
- return new Tuple<UInt16, UInt16, UInt64>(tempMin, tempMax, tempSum);
- }
- private Tuple<UInt16, UInt16, UInt64> GetSubFrameStats(int startIndex, int endIndex)
- {
- UInt16 tempMin = (UInt16)(Math.Pow(2, mfvm.cameras[openCamIndex].bitDepth) - 1);
- UInt16 tempMax = 0;
- UInt64 tempSum = 0;
- for (int i = startIndex; i < endIndex; i++)
- {
- if (acquisition.frameDataShorts[i] < tempMin)
- tempMin = acquisition.frameDataShorts[i];
- if (acquisition.frameDataShorts[i] > tempMax)
- tempMax = acquisition.frameDataShorts[i];
- tempSum += acquisition.frameDataShorts[i];
- }
- return new Tuple<UInt16, UInt16, UInt64>(tempMin, tempMax, tempSum);
- }
Advertisement
Add Comment
Please, Sign In to add comment