public void RefreshMostRecentFrame()
        {
            if (mostRecentFrame == null)
            {
                return;
            }

            //Prepare the temp frame for annotations
            if (tempFrame == null || !tempFrame.SameSizeAs(mostRecentFrame))
            {
                tempFrame = mostRecentFrame.Clone();
            }
            else
            {
                tempFrame.DrawFrame(mostRecentFrame);
            }

            tempFrame.FrameIndex      = mostRecentFrame.FrameIndex;
            tempFrame.ProcessorResult = mostRecentFrame.ProcessorResult;

            if (OnRefreshMostRecentFrame != null)
            {
                OnRefreshMostRecentFrame(tempFrame);
            }

            tempFrame.CopyToWriteableBitmap(canvasBuffer);
        }
Exemple #2
0
 private void OnRefreshMostRecentFrame(Frame frame)
 {
     if (chkShowMotion.IsChecked.Value)
     {
         Processor.Annotate(frame);
     }
 }
        private void ShowFrame(Filters.Frame frame)
        {
            using (var g = Graphics.FromImage(frame.Bitmap))
            {
                var white = new System.Drawing.Pen(System.Drawing.Color.White, 1);
                var black = new System.Drawing.Pen(System.Drawing.Color.Black, 1);

                if (FrameData.ContainsKey(frame.FrameIndex))
                {
                    FrameData[frame.FrameIndex].Select(p => p.Value).ToList().ForEach(p =>
                    {
                        if (p != null)
                        {
                            g.DrawEllipse(white, new RectangleF(p.Value.ToWindowsPoint().ToPointF(), new SizeF(1, 1)));
                            g.DrawEllipse(black, new RectangleF(p.Value.ToWindowsPoint().Moved(-1, -1).ToPointF(), new SizeF(3, 3)));
                        }
                    });
                }
            }


            if (canvasImage == null)
            {
                canvasImage        = new WriteableBitmap(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr24, null);
                videoCanvas.Source = canvasImage;
            }

            frame.CopyToWriteableBitmap(canvasImage);

            videoCanvas_MouseMove(this, null);

            lblTime.Content           = currentFrame.FrameTime.ToString(@"mm\:ss") + " (" + currentFrame.FrameIndex + ")";
            _sliderValueChangedByCode = true;
            sliderTime.Value          = currentFrame.FrameIndex;
        }
        private void OnProcessed(Frame frame)
        {
            var result = (MotionProcessorResult)frame.ProcessorResult;

            if (result == null || Application.Current == null)
            {
                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                if (chkUpdatePlot.IsChecked.Value)
                {
                    try
                    {
                        _chart.AddPoint(result.FrameIndex, result.ChangedPixelsCount);
                    }
                    catch
                    {
                    }
                }

                Activity.Add(new Point(result.FrameIndex, result.ChangedPixelsCount));
                lblChangedPixels.Content = string.Format("Changed Pixels: {0:n0}", result.ChangedPixelsCount);
            });
        }
Exemple #5
0
        private void OnShowFrame(Frame frame)
        {
            if (frame.ProcessorResult != null)
            {
                var frameResult = (EfficientTipAndPERdetector.TipAndPERResult)frame.ProcessorResult;

                treatmentSensor.SensorValue = frameResult.TreatmentSensorValue.ToString();

                modelView.Show(frameResult);
                sectorView.Show(frameResult);
            }
        }
        private void ShowFrame(Filters.Frame frame)
        {
            if (isDrawing)
            {
                return;
            }

            if (Application.Current == null)
            {
                return;
            }

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                if (Application.Current == null)
                {
                    return;
                }

                isDrawing = true;

                //Create WriteableBitmap the first time
                if (canvasBuffer == null || canvasBuffer.Height != frame.Height || canvasBuffer.Width != frame.Width)
                {
                    canvasBuffer  = new WriteableBitmap(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr24, null);
                    Canvas.Source = canvasBuffer;

                    mostRecentFrame = frame.Clone();
                }

                //Limit frame rate shown
                if ((DateTime.Now - prevFrameTime).TotalMilliseconds >= 1000.0 / maxFps)
                {
                    //Save the most recent frame
                    mostRecentFrame.DrawFrame(frame);
                    mostRecentFrame.ProcessorResult = frame.ProcessorResult;
                    mostRecentFrame.FrameIndex      = frame.FrameIndex;

                    if (OnShowFrame != null)
                    {
                        OnShowFrame(frame);
                    }

                    RefreshMostRecentFrame();

                    prevFrameTime = DateTime.Now;
                }

                _sliderValueChangedByCode = true;
                sliderTime.Value          = frame.FramePercentage * 1000;
                lblTime.Content           = frame.FrameTime.ToString();

                //Compute FPS
                var now = DateTime.Now;
                fpsHist.AddLast(now);
                lblFPS.Content = string.Format("FPS: {0:n1}", fpsHist.Count / 1.0);

                while ((now - fpsHist.First()).TotalMilliseconds > 1000)
                {
                    fpsHist.RemoveFirst();
                }

                isDrawing = false;
            }));
        }
        private void StartStopMarking(object sender, RoutedEventArgs e)
        {
            IsMarking = true;

            SetupPlayer();

            videoCanvas.Focus();

            Thread.Sleep(50);
            HideInstructions();


            new Thread(() =>
            {
                while (IsMarking)
                {
                    //for(var i = 0; i < 500; i++)
                    {
                        if (_decoder == null)
                        {
                            SetupPlayer();
                        }

                        lock (_decoder)
                        {
                            _decoder.Stop();
                            _decoder.ClearBuffer();
                            _decoder.SeekTo(iterator.FrameIndex);
                            _decoder.Start(true);

                            while (!_decoder.FramesInBuffer)
                            {
                                Thread.Sleep(5);
                            }

                            if (nextFrame != null)
                            {
                                nextFrame.Dispose();
                            }

                            nextFrame = _decoder.PlayNextFrame();
                        }
                    }

                    if (currentFrame != null)
                    {
                        currentFrame.Dispose();
                    }

                    currentFrame = nextFrame;

                    Dispatcher.Invoke(() =>
                    {
                        lblActivePartName.Text = TemplateView.Current.CurrentPartName;
                        ShowFrame(currentFrame);

                        GC.Collect();
                    });



                    ReadyForNextFrame = false;

                    while (!ReadyForNextFrame && IsMarking)
                    {
                        Thread.Sleep(5); //Wait for position data (use value < smallest inter-click interval)
                    }

                    //Store the position data
                    if (!FrameData.ContainsKey(currentFrame.FrameIndex))
                    {
                        FrameData[currentFrame.FrameIndex] = new Dictionary <string, System.Drawing.Point?>();
                    }

                    if (_capturedMousePosition != null)
                    {
                        FrameData[currentFrame.FrameIndex][TemplateView.Current.CurrentPartName] = _capturedMousePosition;
                    }

                    UpdateReward();

                    if (iterator.IsAtEndOfBurstOrSequenceOrVideo && iterator.IsAtEndOfBatch)
                    {
                        iterator.AdvanceBurst();
                        templateView.CurrentPartIndex = iterator.BatchPartIndex;
                        IsMarking = false;
                        ShowInstructions();
                        return;
                    }

                    if (iterator.IsAtEndOfBurstOrSequenceOrVideo)
                    {
                        iterator.AdvanceBurst();
                        templateView.CurrentPartIndex = iterator.BatchPartIndex;
                        SetupPlayer(); //Rewind to first frame
                        IsMarking = false;
                        ShowInstructions();
                        return;
                    }

                    iterator.AdvanceBurst();

                    Thread.Sleep(10);
                }
            }).Start();
        }
Exemple #8
0
 private void OnRefreshMostRecentFrame(Frame frame)
 {
     Processor.Annotate(frame);
 }
        internal void Show(EfficientTipAndPERdetector.TipAndPERResult processorResult)
        {
            var width  = (int)image.Width;
            var height = (int)image.Height;

            //Create WriteableBitmap the first time
            if (canvasBuffer == null)
            {
                clearFrame = new Frame(width, height);

                canvasBuffer = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr24, null);
                image.Source = canvasBuffer;
            }

            using (var gfx = Graphics.FromImage(clearFrame.Bitmap))
            {
                gfx.Clear(Color.White);
            }

            if (processorResult?.Left?.SectorCounts != null)
            {
                clearFrame.MarkSectors(
                    sectors: processorResult.Left.SectorCounts,
                    headCtrX: width / 2,
                    headCtrY: height / 2,
                    headHeight: height / 2,
                    headAngle: 0,
                    color: Color.Black,
                    isRight: false
                    );

                leftDomSec.Content  = processorResult.Left.DominantSector;
                leftSecMode.Content = processorResult.Left.TopAngle + "°";
            }
            else
            {
                leftDomSec.Content  = "-";
                leftSecMode.Content = "-";
            }



            if (processorResult?.Right?.SectorCounts != null)
            {
                clearFrame.MarkSectors(
                    sectors: processorResult.Right.SectorCounts,
                    headCtrX: width / 2,
                    headCtrY: height / 2,
                    headHeight: height / 2,
                    headAngle: 0,
                    color: Color.Black,
                    isRight: true
                    );

                rightDomSec.Content  = processorResult.Right.DominantSector;
                rightSecMode.Content = processorResult.Right.TopAngle + "°";
            }
            else
            {
                rightDomSec.Content  = "-";
                rightSecMode.Content = "-";
            }

            clearFrame.CopyToWriteableBitmap(canvasBuffer);
        }