private void DoUpdaterWork()
        {
            while (true)
            {
                if (m_updateState == UpdateState.NotNeeded)
                {
                    continue;
                }

                // make copies
                Contour inputContour   = null;
                bool    checkBoth      = false;
                bool    autoUpdateInfo = false;

                Invoke(() =>
                {
                    inputContour   = ContourInput.Contour;
                    checkBoth      = CheckBothDirections;
                    autoUpdateInfo = AutoUpdateInfoInCollection;
                });

                if (inputContour == null)
                {
                    continue;
                }

                ContoursMatcher.Match bestMatch = m_matcher.GetMatch(inputContour, true);

                if (bestMatch == null)
                {
                    continue;
                }

                Invoke(() => BestMatchContourInfoPresenter.ContourInfo = bestMatch.FamiliarContour);

                // Expensive operation for big collections. Do with background priority to increase responsibility
                if (m_updateState == UpdateState.ForceUpdate || autoUpdateInfo)
                {
                    InvokeAsync(() =>
                    {
                        foreach (var cInfo in Contours)
                        {
                            cInfo.SendDynamicInfosChangedNotification();
                        }
                    }, DispatcherPriority.Background);
                }

                m_updateState = UpdateState.NotNeeded;
            }
        }
Exemplo n.º 2
0
        private void ProcessFrame()
        {
            UnmanagedImage unpreprocessedCopy = m_currentUnpreprocessed.Clone();

            m_currentPreprocessed = m_preprocessingFilters.Apply(unpreprocessedCopy);

            Bitmap   image    = new Bitmap(m_currentPreprocessed.Width, m_currentPreprocessed.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics graphics = Graphics.FromImage(image);

            if (m_showMode == ShowImageMode.Source)
            {
                graphics.DrawImageUnscaled(m_currentUnpreprocessed.ToManagedImage(), 0, 0);
            }
            else
            {
                graphics.DrawImageUnscaled(m_currentPreprocessed.ToManagedImage(), 0, 0);
            }

            m_blobExtractor.ProcessImage(m_currentPreprocessed);
            var blobs = m_blobExtractor.GetObjects(m_currentPreprocessed, false);

            lock (m_findedContours)
            {
                m_findedContours.Clear();
                foreach (var blob in blobs)
                {
                    Contour contour = m_extractor.Extract(blob.Image);
                    m_findedContours.Add(new FindedContourInfo()
                    {
                        Contour         = contour.BringLength(m_targetContoursLenght),
                        CenterOfGravity = blob.CenterOfGravity,
                        Rect            = blob.Rectangle
                    });
                }

                foreach (var finded in m_findedContours)
                {
                    ContoursMatcher.Match bestMatch = m_matcher.GetMatch(finded.Contour);

                    if (bestMatch != null)
                    {
                        var text         = string.Format("{0}", bestMatch.FamiliarContour.Description, bestMatch.MaxNSP.AbsoluteValue());
                        var textPosition = new PointF(finded.Rect.Left + finded.Rect.Width / 2, finded.Rect.Bottom);

                        graphics.DrawString(text, m_font, m_textBrush, textPosition);

                        if (m_showAngle)
                        {
                            graphics.DrawString(string.Format("{0:F0}°", bestMatch.MaxNSP.ArgumentDegrees()), m_font, m_textBrush, PointF.Add(textPosition, new Size(0, 13)));
                        }

                        if (m_showBoundingRect)
                        {
                            graphics.DrawRectangle(Pens.Green, finded.Rect);
                        }
                    }
                }
            }

            ImageBox.Image       = image;
            BlobsCountLabel.Text = string.Format("blobs count: {0}", blobs.Length);
        }