Ejemplo n.º 1
0
 public Rectangle(Child Parent, ImageSection ImgSec)
     : base(Parent, ImgSec, 4)
 {
 }
Ejemplo n.º 2
0
 protected Polygon(Child Parent, ImageSection ImgSec, int VertexCount)
     : base(Parent, ImgSec)
 {
     if (VertexCount <= 2) throw new InvalidOperationException("Vertices count must be greater than 2");
     mVerticeCount = VertexCount;
 }
Ejemplo n.º 3
0
 public Triangle(Child Parent, ImageSection ImgSec)
     : base(Parent, ImgSec, 3)
 {
 }
Ejemplo n.º 4
0
 public Ellipse(Child Parent, ImageSection ImgSec)
     : base(Parent, ImgSec)
 {
     this.HardFit();
 }
Ejemplo n.º 5
0
        { return 0d; } //NEEDS OVERRIDE using new keyword

        internal Child(Child Parent, ImageSection Img)
        {
            mImgSec = Img;
            mParent = Parent;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ImgSec"></param>
        /// <param name="ColorForgive"></param>
        /// <param name="ColorDetail"></param>
        /// <param name="MinMargin"></param>
        /// <returns></returns>
        internal static Child[] ScanImageSection(ImageSection ImgSec, int ColorForgive, int ColorDetail, int MinMargin, Child Parent = null)
        {
#if GUIOUTPUT
            mScannedPx = 0;
            int MaxSize = ImgSec.Width * ImgSec.Height;
            frmImgSecDisplay DisplayOut = null;
            //DisplayOut.Show();
            //Master.sInvokable.Invoke(Master.sAddable, null => {return new frmImgSecDisplay();}, DisplayOut);
            MakeForm NewDisp = delegate() { return new frmImgSecDisplay(); };
            AssignForm AssDisp = delegate(System.Windows.Forms.Form ToAssign) { DisplayOut = (frmImgSecDisplay)ToAssign; };
            Master.sInvokable.Invoke(Master.sAddable, new object[] { NewDisp, AssDisp });
#endif
            //Break the image into ImageSections
            List<ImageSection> Sections = new List<ImageSection>();
            ImageSectionFactory Factory;
            for (int y = 0; y < ImgSec.Height; y++)
            {
                for (int x = 0; x < ImgSec.Width; x++)
                {
                    if (ImgSec.GetPixel(x, y).A == byte.MaxValue)
                    {
                        Factory = new ImageSectionFactory(new Point(x, y), ColorForgive, ColorDetail
#if GUIOUTPUT
                            ,DisplayOut
#endif
                            );
                        Sections.Add(Factory.Recognize(ref ImgSec, x, y));
#if GUIOUTPUT
                        UpdateDisplay((mScannedPx += Factory.SelectedPixels().Count()), MaxSize, 0);
#endif
                    }
                }
            }

            Sections.RemoveAll(imsec => imsec == null);
            //Figure out if it just selected the whole thing. If so, cancel the scan
            if (Sections.Count == 1 && Sections[0].Size == ImgSec.Size)
                return new Child[0];

            //Figure out which ones of those are too small and should be discounted
            for (int remove = 0; remove < Sections.Count; remove++)
            {
                if (Sections[remove].PixelsUsed().Length <= MinMargin) Sections.RemoveAt(remove);
            }
            Sections.TrimExcess();

            // Once that's done, turn the remaining Image Sections into Children
            Child[] Children = new Child[Sections.Count];
#if MULTITHREAD
            Task<Child>[] Tasks = new Task<Child>[Sections.Count];
#endif
            for (int i = 0; i < Sections.Count; i++)
            {
#if MULTITHREAD
                Tasks[i] = new Task<Child>(s => Child.FromSection((Child)((object[])s)[0], (ImageSection)((object[])s)[1]), new object[]{Parent, Sections[i]});
                Tasks[i].Start();
#else
                Children[i] = Child.FromSection(Parent, Sections[i]);
#endif

#if GUIOUTPUT
                UpdateDisplay(MaxSize, MaxSize, 1);
#endif
            }
#if MULTITHREAD
            try
            {
                while (Tasks.Any(t => !t.IsCompleted)) Tasks.First(t => !t.IsCompleted).Wait();
            }
            catch (NullReferenceException) { }
            for (int i = 0; i < Tasks.Length; i++)
            {
                Children[i] = Tasks[i].Result;
            }
#endif

            return Children;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Parent"></param>
        /// <param name="ImgSec"></param>
        /// <returns></returns>
        internal static Child FromSection(Child Parent, ImageSection ImgSec)
        {
            Func<ImageSection, double> BestFitter = null;
            double BestFit = 0d;
            double temp;
            sRegisteredChecks.ForEach(f => { if (BestFit < (temp = f(ImgSec))) { BestFitter = f; BestFit = temp; } });

            if (BestFit == 0d) throw new InvalidOperationException("No shapes are registered, or they are not matching any pixels.");

            return sRegisteredConstructs[sRegisteredChecks.IndexOf(BestFitter)](Parent, ImgSec);
        }