Exemplo n.º 1
0
        private int[,] GetCurrentImageFromBufferedFrame(BufferedFrameInfo bufferedFrame)
        {
            if (bufferedFrame.IsIntegratedFrame)
            {
                int counter = 0;

                if (bufferedFrame.LastIntegratedFrameIndex < bufferedFrame.FirstIntegratedFrameIndex)
                {
                    aviTools.InitFrameIntegration(Width, Height);

                    // Add all frames from bufferedFrame.FirstIntegratedFrameIndex to allImagesPixels.Count
                    for (int i = bufferedFrame.FirstIntegratedFrameIndex; i <= allImagesPixels.Count - 1; i++)
                    {
                        int[,] frame = GetCurrentImageNoBuffering(i);
                        aviTools.AddIntegrationFrame(frame);
                        counter++;
                    }

                    // Add all frames from 0 to bufferedFrame.LastIntegratedFrameIndex
                    for (int i = 0; i <= bufferedFrame.LastIntegratedFrameIndex; i++)
                    {
                        int[,] frame = GetCurrentImageNoBuffering(i);
                        aviTools.AddIntegrationFrame(frame);
                        counter++;
                    }

                    lastBufferedImage = aviTools.GetResultingIntegratedFrame(Width, Height);
                }
                else
                {
                    // Add all frames from bufferedFrame.FirstIntegratedFrameIndex to bufferedFrame.LastIntegratedFrameIndex

                    aviTools.InitFrameIntegration(Width, Height);

                    for (int i = bufferedFrame.FirstIntegratedFrameIndex; i <= bufferedFrame.LastIntegratedFrameIndex; i++)
                    {
                        int[,] frame = GetCurrentImageNoBuffering(i);
                        aviTools.AddIntegrationFrame(frame);
                        counter++;
                    }

                    lastBufferedImage = aviTools.GetResultingIntegratedFrame(Width, Height);
                }
            }
            else
            {
                lastBufferedImage = GetCurrentImageNoBuffering(bufferedFrame.FirstIntegratedFrameIndex);
            }

            return(lastBufferedImage);
        }
Exemplo n.º 2
0
        public void GetCurrentImage(out int[,] currentFrame, out long currentFrameNo, out byte[] previewBitmapBytes)
        {
            if (errorBitmap != null)
            {
                currentFrame       = errorPixels;
                currentFrameNo     = this.currentFrameNo;
                previewBitmapBytes = cameraImage.GetBitmapBytes(errorBitmap);
            }
            else
            {
                if (playbackBufferSize > 0)
                {
                    lock (syncRoot)
                    {
                        if (playbackBuffer.Count > 0)
                        {
                            nextBufferedFrame = playbackBuffer.Dequeue();
                        }
                        else
                        {
                            // There is no new buffered frame
                        }
                    }

                    currentFrame   = GetCurrentImageFromBufferedFrame(nextBufferedFrame);
                    currentFrameNo = nextBufferedFrame.CurrentFrameNo;
                }
                else
                {
                    currentFrame   = GetCurrentImageFromBufferedFrame(this.currentFrame);
                    currentFrameNo = this.currentFrame.CurrentFrameNo;
                }

                cameraImage.SetImageArray(currentFrame, width, height, SensorType.Monochrome);
                previewBitmapBytes = cameraImage.GetDisplayBitmapBytes();
            }
        }
Exemplo n.º 3
0
        private void PlayerWorkerThread(object state)
        {
            DebugTrace.TraceInfo(string.Format("Camera started. Buffer size: {0}", playbackBufferSize));

            BufferedFrameInfo newFrame;

            lock (syncRoot)
            {
                playbackBuffer.Clear();
                newFrame = new BufferedFrameInfo()
                {
                    FirstIntegratedFrameIndex = -1
                };
                integratedFramesSoFar = 0;
            }

            lastBufferedImage = new int[height, width];
            isRecording       = false;

            Profiler.ResetAndStartTimer(100);

            while (running)
            {
                currentFrameIndex++;

                long startTicks = Profiler.GetTicks();

                if (currentFrameIndex > allImagesPixels.Count - 1)
                {
                    Profiler.StopTimer(100);
                    double msForAllImages = Profiler.GetElapsedMillisecondsForTimer(100);
                    double fps            = allImagesPixels.Count * 1000.0 / msForAllImages;
                    DebugTrace.TraceVerbose(string.Format("Camera running at {0} fps", fps.ToString("#0.00")));

                    currentFrameIndex = 0;

                    Profiler.ResetAndStartTimer(100);
                }

                if (playbackBufferSize > 0)
                {
                    lock (syncRoot)
                    {
                        while (playbackBuffer.Count > playbackBufferSize)
                        {
                            playbackBuffer.Dequeue();
                        }

                        if (newFrame.FirstIntegratedFrameIndex == -1)
                        {
                            newFrame.FirstIntegratedFrameIndex = currentFrameIndex;
                            newFrame.LastIntegratedFrameIndex  = -1;
                        }

                        if (integration > 1)
                        {
                            integratedFramesSoFar++;

                            if (integratedFramesSoFar >= integration)
                            {
                                newFrame.LastIntegratedFrameIndex = currentFrameIndex;
                                newFrame.IsIntegratedFrame        = true;
                            }
                        }
                        else
                        {
                            newFrame.LastIntegratedFrameIndex = newFrame.FirstIntegratedFrameIndex;
                            newFrame.IsIntegratedFrame        = false;
                        }

                        if (newFrame.LastIntegratedFrameIndex != -1)
                        {
                            currentFrameNo++;
                            newFrame.CurrentFrameNo = currentFrameNo;

                            playbackBuffer.Enqueue(newFrame);

                            newFrame = new BufferedFrameInfo()
                            {
                                FirstIntegratedFrameIndex = -1
                            };
                            integratedFramesSoFar = 0;
                        }
                    }
                }
                else
                {
                    // No buffering

                    if (newFrame.FirstIntegratedFrameIndex == -1)
                    {
                        newFrame.FirstIntegratedFrameIndex = currentFrameIndex;
                        newFrame.LastIntegratedFrameIndex  = -1;
                    }

                    if (integration > 1)
                    {
                        integratedFramesSoFar++;

                        if (integratedFramesSoFar >= integration)
                        {
                            newFrame.LastIntegratedFrameIndex = currentFrameIndex;
                            newFrame.IsIntegratedFrame        = true;
                        }
                    }
                    else
                    {
                        newFrame.LastIntegratedFrameIndex = newFrame.FirstIntegratedFrameIndex;
                        newFrame.IsIntegratedFrame        = false;
                    }

                    if (newFrame.LastIntegratedFrameIndex != -1)
                    {
                        currentFrameNo++;
                        newFrame.CurrentFrameNo = currentFrameNo;

                        currentFrame = newFrame;
                        newFrame     = new BufferedFrameInfo()
                        {
                            FirstIntegratedFrameIndex = -1
                        };
                        integratedFramesSoFar = 0;
                    }

                    if (isRecording)
                    {
                        int[,] pixels = GetCurrentImageFromBufferedFrame(currentFrame);
                        aviTools.AddAviVideoFrame(pixels);
                    }
                }

                long endTicks    = Profiler.GetTicks();
                int  msThisFrame = (int)Profiler.TranslateTicksToMilliseconds(endTicks - startTicks);

                if (msThisFrame < frameWaitTime)
                {
                    Thread.Sleep(frameWaitTime - msThisFrame);
                }

                if (stopRecordingRequested)
                {
                    stopRecordingRequested = false;
                    isRecording            = false;
                }
            }

            DebugTrace.TraceInfo("Camera stopped");
        }