Beispiel #1
0
        public static IPicAccess ObjectToPic_RegionOfInterest(ObjectPoints o, IPicAccess originalPic)
        {
            MyPic pic = new MyPic(o.Rect.Size, MyPic.Invert(o.Type));

            foreach (Point p1 in o.Points)
            {
                pic.setPixel(p1.X - o.XLeft, p1.Y - o.YTop, o.Type); //mg was  PixelInfo.Black);
            }
            return(pic);
        }
Beispiel #2
0
        public static IPicAccess ObjectToPic(ObjectPoints o, IPicAccess originalPic)
        {
            MyPic pic = new MyPic(originalPic.getDimenion(), MyPic.Invert(o.Type));

            foreach (Point p1 in o.Points)
            {
                pic.setPixel(p1.X, p1.Y, o.Type);
            }
            return(pic);
        }
Beispiel #3
0
        public MyPic(ObjectPoints objectPoints)
        {
            this.Size           = objectPoints.Rect.Size;
            this.pTreshold      = MyPicPixelInfoEnum.e3_mid;
            this.PixelInfoArray = new MyPicPixelInfoEnum[(Size.Width * Size.Height) + 1];

            foreach (Point p1 in objectPoints.Points)
            {
                Point p00      = new Point(p1.X - objectPoints.XLeft, p1.Y - objectPoints.YTop);
                int   arrayPos = p00.X + (p00.Y * this.Size.Width);
                this.PixelInfoArray[arrayPos] = MyPicPixelInfoEnum.e7;
            }
        }
Beispiel #4
0
 internal static bool Contains(List <ObjData> list, ObjectPoints points)
 {
     foreach (ObjData objData in list)
     {
         if ((objData.Width == points.Rect.Width) && (objData.Height == points.Rect.Height))
         {
             if (points.CalcHashString() == objData.Hash)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #5
0
        public void DoDetection(dOnDetectObject cb, bool debug, int minSize)
        {
            bool stayInLoop = true;

            #region theLoop
            SlowDown slowdown = new SlowDown();
            for (int y = 0; ((stayInLoop) && (y < Pic.getDimenion().Height)); y++)
            {
                for (int x = 0; ((stayInLoop) && (x < Pic.getDimenion().Width)); x++)
                {
                    slowdown.Next();

                    PixelInfo i = Pic.getPixel(x, y);
                    switch (i)
                    {
                    case PixelInfo.White:
                        ObjectPoints whites = new ObjectPoints(i);
                        onPoint_AddInvalidateExpand(whites, x, y);
                        whites.DoneAdding();
                        WhiteObjectList.Add(whites);
                        onDebug(debug, minSize, whites);
                        if (!cb(whites, Pic))
                        {
                            stayInLoop = false;
                        }
                        break;

                    case PixelInfo.Black:
                        ObjectPoints black = new ObjectPoints(i);
                        onPoint_AddInvalidateExpand(black, x, y);
                        black.DoneAdding();
                        BlackObjectList.Add(black);
                        onDebug(debug, minSize, black);
                        if (!cb(black, Pic))
                        {
                            stayInLoop = false;
                        }
                        break;

                    case PixelInfo.Processed:
                        break;

                    default:
                        break;
                    }
                }
            }
            #endregion
        }
Beispiel #6
0
 private void onDebug(bool debug, int minSize, ObjectPoints points)
 {
     if (debug)
     {
         if ((points.Rect.Height >= minSize) && (points.Rect.Width >= minSize))
         {
             MyPic  debPic   = new MyPic(points);
             int    area     = points.Rect.Width * points.Rect.Height;
             string hash     = points.CalcHashString();
             string fileName = String.Format("debPic_{0}_{1}_{2}_w{3}_h{4}_{5}",
                                             points.XLeft, points.YTop, area, points.Rect.Width, points.Rect.Height, onDebugCount++);
             debPic.ToFile(fileName);
             System.IO.File.WriteAllText(fileName + "hash.txt", hash);
             debPic = null;
         }
     }
 }
Beispiel #7
0
        private void onPoint_AddInvalidateExpand(ObjectPoints curHole, int x, int y)
        {
            curHole.Add(x, y);
            invalidate(x, y);

            List <Point> PointsToTry = new List <Point>();

            addPotentialPoints(PointsToTry, x, y, curHole.Type);
            while (PointsToTry.Count > 0)
            {
                Point pTry = PointsToTry[0];
                PointsToTry.RemoveAt(0);
                if (curHole.Type == Pic.getPixel(pTry.X, pTry.Y))
                {
                    curHole.Add(pTry.X, pTry.Y);
                    invalidate(pTry.X, pTry.Y);
                    addPotentialPoints(PointsToTry, pTry.X, pTry.Y, curHole.Type);
                }
            }
        }