Exemple #1
0
 /// <summary>
 /// match handler
 /// </summary>
 internal void MatchHandler(GlyphBase o, MatchingInfo i)
 {
     if (NewGlyphMatch != null)
     {
         NewGlyphMatch(this, new GlyphMatchEventArgs(this, o, i));
     }
 }
Exemple #2
0
 /// <summary>
 /// Instantiate a new GlyphPanel object
 /// </summary>
 /// <param name="glyph"></param>
 public GlyphPanel(GlyphBase glyph)
 {
     _associatedGlyph = glyph;
     _padding         = 0.0;
     _position        = new PointF(0f, 0f);
     _size            = SizeF.Empty;
     _layout          = PanelLayoutMode.None;
     _opacity         = 1.0;
 }
Exemple #3
0
        /// <summary>
        /// Try to find the GlyphBase specified within second GlyphBase
        /// </summary>
        /// <param name="glyphToFind">The GlyphBase to look for</param>
        /// <param name="glyphToParse">The GlyphBase to search</param>
        /// <param name="errorMax">The maximum number of pixel mismatching (normalized percentage)</param>
        /// <returns>true if match, false otherwise</returns>
        public bool FindSingleGlyph(GlyphBase glyphToFind, GlyphBase glyphToParse, double errorMax)
        {
            _glyphToFind     = glyphToFind;
            _glyphSearched   = glyphToParse;
            MatchFoundEvent += new MatchFoundEventHandler(GlyphComparator_MatchFoundInternal);

            IImageAdapter imageToParse = glyphToParse.Render();
            IImageAdapter imageToFind  = glyphToFind.Render();

            return(FindImageAdapter(imageToParse, imageToFind, errorMax));
        }
Exemple #4
0
 /// <summary>
 /// The constructor
 /// </summary>
 public GlyphLayout(GlyphBase glyphBase) : this()
 {
     _glyphBase = glyphBase;
 }
Exemple #5
0
        /// <summary>
        /// Find the all the GlyphBase specified in the Array within the GlyphModel::Target
        /// </summary>
        /// <param name="glyphsToFind">The GlyphBase to find</param>
        /// <param name="glyphModel">The GlyphModel to use</param>
        /// <returns>The number of match found (max of one per glyph found)</returns>
        public int FindGlyphs(GlyphBase[] glyphsToFind, GlyphModel glyphModel)
        {
            int retVal = 0;

            _glyphSearched   = glyphModel;
            MatchFoundEvent += new MatchFoundEventHandler(GlyphComparator_MatchFoundInternal);

            IImageAdapter targetFiltered = ImageUtility.ClipImageAdapter(glyphModel.Target, new Rectangle((int)glyphModel.Panel.Position.X, (int)glyphModel.Panel.Position.Y, (int)glyphModel.Panel.Size.Width, (int)glyphModel.Panel.Size.Height));
//                    IImageAdapter targetFiltered = ImageUtility.ClipImageAdapter(glyphModel.Target, new Rectangle((int)glyphModel.Layout.Position.X, (int)glyphModel.Layout.Position.Y, (int)glyphModel.Layout.Size.Width, (int)glyphModel.Layout.Size.Height));

            // Filter Image (Only needed if one or more "GlyphBase::EdgesOnly" property is true)
            SaturateEdgeFilter edgeFilter = new SaturateEdgeFilter();

            edgeFilter.ColorBelowThresold = (ColorByte)Color.White;
            edgeFilter.ColorAboveThresold = (ColorByte)Color.Red;
            edgeFilter.Threshold          = 0;
            if (GlyphUseEdgeOnly(glyphsToFind))
            {
                targetFiltered = edgeFilter.Process(targetFiltered);
            }

            // Render every glyphs (needed because Glyph overlap would mess up the resulting bmp otherwise)
            IImageAdapter renderSurface = null;

            if (glyphModel.GeneratedImage != null)
            {
                renderSurface = glyphModel.GeneratedImage;
            }
            else
            {
                renderSurface = new ImageAdapter(glyphModel.Size.Width, glyphModel.Size.Height, ColorByte.Empty);
                renderSurface = RenderGlyphs(glyphsToFind, renderSurface);
            }

            // Capture images
            Hashtable glyphBitmapHash = new Hashtable(glyphModel.Glyphs.Count);

            for (int t = 0; t < glyphModel.Glyphs.Count; t++)
            {
                GlyphBase glyph = (GlyphBase)glyphModel.Glyphs[t];

                Rectangle     area         = new Rectangle(glyph.ComputedLayout.Position.X, glyph.ComputedLayout.Position.Y, (int)Math.Min(glyph.ComputedLayout.Size.Width, glyphModel.Panel.Size.Width - glyph.ComputedLayout.Position.X + .5), (int)Math.Min(glyph.ComputedLayout.Size.Height, glyphModel.Panel.Size.Height - glyph.ComputedLayout.Position.Y + .5));
                IImageAdapter clippedImage = ImageUtility.ClipImageAdapter(renderSurface, area);
                if (glyphBitmapHash.Contains(glyph) == false)
                {
                    glyphBitmapHash.Add(glyph, clippedImage);
                }
                else
                {
                    // Duplicate, remove it from the collection
                    glyphModel.Glyphs.RemoveAt(t);
                    t--;
                }
            }

            // Try to match ever Glyph in the collection
            IDictionaryEnumerator iter = glyphBitmapHash.GetEnumerator();

            while (iter.MoveNext())
            {
                GlyphBase glyph = (GlyphBase)iter.Key;
                _glyphToFind = glyph;
                IImageAdapter imageAdapter = (ImageAdapter)iter.Value;

                if (glyph.CompareInfo.EdgesOnly)
                {
                    imageAdapter = edgeFilter.Process(imageAdapter);
                }
                bool found = FindImageAdapter(targetFiltered, imageAdapter, glyph.CompareInfo.ErrorMax);
                if (found)
                {
                    retVal++;
                }
            }

            return(retVal);
        }
Exemple #6
0
 /// <summary>
 /// 'Ctor
 /// </summary>
 /// <param name="glyphModel"></param>
 /// <param name="glyphBase"></param>
 /// <param name="matchInfo"></param>
 public GlyphMatchEventArgs(GlyphModel glyphModel, GlyphBase glyphBase, MatchingInfo matchInfo)
 {
     ModelGlyph = glyphModel;
     BaseGlyph  = glyphBase;
     MatchInfo  = matchInfo;
 }