Esempio n. 1
0
 public RabbitEngineEventArgs(Rabbit r, RabbitEngineEventType rEA)
 {
     Rabbit    = r;
     EventType = rEA;
 }
Esempio n. 2
0
 public RabbitEventArgs(Rabbit r, SquareTUI oC, RabbitEventType rET)
 {
     Rabbit     = r;
     ObjectCode = oC;
     EventType  = rET;
 }
Esempio n. 3
0
        public void ProcessImage(Image <Gray, Byte> image)
        {
            IList <Rabbit>    fRabbits = new List <Rabbit>();
            IList <Rabbit>    rRabbits = new List <Rabbit>();
            IList <SquareTUI> foundLTUIs = null, foundPTUIs = null, foundTUIs = new List <SquareTUI>();

            if (settings.supportLTUIs)
            {
                currentType       = SquareTUIType.LightTUI;
                contourThreshold  = settings.lContourThreshold;
                axisLength        = settings.lAxisLength;
                locationThreshold = settings.lLocationThreshold;
                minArea           = settings.lMinArea;
                maxArea           = settings.lMaxArea;
                foundLTUIs        = PerformDetection(image);
            }

            if (settings.supportPTUIs)
            {
                currentType       = SquareTUIType.PaperTUI;
                contourThreshold  = settings.pContourThreshold;
                axisLength        = settings.pAxisLength;
                locationThreshold = settings.pLocationThreshold;
                minArea           = settings.pMinArea;
                maxArea           = settings.pMaxArea;
                foundPTUIs        = PerformDetection(image);
            }

            if (foundLTUIs != null)
            {
                foundTUIs = foundLTUIs;
            }
            if (foundPTUIs != null)
            {
                foreach (SquareTUI sTUI in foundPTUIs)
                {
                    foundTUIs.Add(sTUI);
                }
            }

            foreach (SquareTUI foundTUI in foundTUIs)
            {
                float rabbitLoctaionThreshold = (float)(settings.pAxisLength / 1.2);

                //The same code in the "same" location
                Rabbit existingR = currentRabbits.SingleOrDefault(tmp => tmp.ObjectCode.Value == foundTUI.Value && tmp.ObjectCode.GetDistance(foundTUI) < rabbitLoctaionThreshold);
                //One in the "same" location
                Rabbit closestR = currentRabbits.OrderBy(tmp => tmp.ObjectCode.GetDistance(foundTUI)).FirstOrDefault(tmp => tmp.ObjectCode.GetDistance(foundTUI) < rabbitLoctaionThreshold);

                if (existingR == null && closestR != null)
                {
                    existingR = closestR;
                }

                if (existingR == null)
                {
                    //Then it's new and has to be added
                    Rabbit newRabbit = new Rabbit(++rabbitIdCons, foundTUI);
                    newRabbit.SourceImageWidth  = image.Width;
                    newRabbit.SourceImageHeight = image.Height;

                    currentRabbits.Add(newRabbit);
                    fRabbits.Add(newRabbit);
                    OnRabbitAdded(newRabbit);
                    continue;
                }

                //It already existed
                existingR.ObjectCode = foundTUI;
                fRabbits.Add(existingR);
                OnRabbitUpdated(existingR);
                continue;
            }

            foreach (Rabbit formerR in currentRabbits)
            {
                if (!fRabbits.Contains(formerR))
                {
                    rRabbits.Add(formerR);
                }
            }

            foreach (Rabbit formerR in rRabbits)
            {
                currentRabbits.Remove(formerR);
                OnRabbitRemoved(formerR);
            }
        }