示例#1
0
        private void CalculateRectanglesOfDifferences(ComparableBitmap[] bitmap1, ComparableBitmap[] bitmap2)
        {
            if ((bitmap1 == null) || (bitmap2 == null))
            {
                return;
            }

            List <RectanglesWithSimilarity> rectangles = new List <RectanglesWithSimilarity>();
            float similarity;

            for (int i = 0; i < bitmap1.Length; i++)
            {
                if (_highlightStop)
                {
                    return;
                }
                similarity = Comparator.Similarity(bitmap1[i].GrayscaleData, bitmap2[i].GrayscaleData);
                if (similarity < m_options.resultsOptions.DifferenceThreshold)
                {
                    rectangles.Add(new RectanglesWithSimilarity(bitmap1[i].Rect, similarity));
                }
            }

            if (m_options.resultsOptions.NotHighlightIfFragmentsMoreThan && rectangles.Count > m_options.resultsOptions.NotHighlightMaxFragments)
            {
                return;
            }

            if (!m_options.resultsOptions.HighlightAllDifferences)
            {
                if (HighlightCompleteEvent != null)
                {
                    rectangles.Sort(delegate(RectanglesWithSimilarity a, RectanglesWithSimilarity b)
                    {
                        return(a.similarity.CompareTo(b.similarity));
                    });
                    RectanglesWithSimilarity[] src = rectangles.ToArray();
                    List <Rectangle>           dst = new List <Rectangle>();
                    for (int i = 0, n = Math.Min(src.Length, m_options.resultsOptions.MaxFragmentsForHighlight); i < n; ++i)
                    {
                        dst.Add(src[i].rectangle);
                    }
                    HighlightCompleteEvent(dst);
                }
            }

            if (HighlightCompleteEvent != null)
            {
                RectanglesWithSimilarity[] src = rectangles.ToArray();
                List <Rectangle>           dst = new List <Rectangle>();
                for (int i = 0; i < src.Length; ++i)
                {
                    dst.Add(src[i].rectangle);
                }
                HighlightCompleteEvent(dst);
            }
        }
        private void CalculateRectanglesOfDifferences(ComparableBitmap[] bitmap1, ComparableBitmap[] bitmap2)
        {
            if ((bitmap1 == null) || (bitmap2 == null))
            {
                return;
            }

            List <RectanglesWithSimilarity> rectangles = new List <RectanglesWithSimilarity>();
            float similarity;

            for (int i = 0; i < bitmap1.Length; i++)
            {
                if (_highlightStop)
                {
                    return;
                }
                similarity = Comparator.Similarity(bitmap1[i].GrayscaleData, bitmap2[i].GrayscaleData);
                if (similarity < m_options.resultsOptions.DifferenceThreshold)
                {
                    rectangles.Add(new RectanglesWithSimilarity(bitmap1[i].Rect, similarity));
                }
            }

            if (m_options.resultsOptions.NotHighlightIfFragmentsMoreThan && rectangles.Count > m_options.resultsOptions.NotHighlightMaxFragments)
            {
                return;
            }

            if (!m_options.resultsOptions.HighlightAllDifferences)
            {
                if (HighlightCompleteEvent != null)
                {
                    HighlightCompleteEvent((from rect in rectangles
                                            orderby rect.similarity descending
                                            select rect.rectangle).Take(m_options.resultsOptions.MaxFragmentsForHighlight).ToList());
                }
            }

            if (HighlightCompleteEvent != null)
            {
                HighlightCompleteEvent((from rect in rectangles
                                        select rect.rectangle).ToList());
            }
        }