Beispiel #1
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 #2
0
        public charQuater(IPicAccess pic4x6)
        {
            if ((pic4x6.getDimenion() != new Size(4, 6)))
            {
                throw new ArgumentException("not 4x6");
            }
            pic4x6.ToFile("pic4x6");

            cornerStr  = "";
            cornerStr += getPixelChar(pic4x6, 3, 0);
            cornerStr += getPixelChar(pic4x6, 0, 0);
            cornerStr += getPixelChar(pic4x6, 0, 5);
            cornerStr += getPixelChar(pic4x6, 3, 5);

            ObjectDetection det = new ObjectDetection(pic4x6, false, true);

            det.DoDetection(new dOnDetectObject(delegate(ObjectPoints points, IPicAccess originalPic)
            {
                if (points.Type == PixelInfo.Black)
                {
                    if (points.Points.Contains(topLeft) && points.Points.Contains(bottomRight))
                    {
                        topLeftToBottomRight = true;
                    }
                    if (points.Points.Contains(topRight) && points.Points.Contains(bottomLeft))
                    {
                        topRightToBottomLeft = true;
                    }
                }
                return(true);
            }), false, 0);
        }
Beispiel #3
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 #4
0
        public static char RecogniseChar(IPicAccess pic)
        {
            pic.ToFile("RecogniseChar");
            Size pSize   = pic.getDimenion();
            Size sBig    = new Size(7, 12);
            Size sSmall4 = new Size(4, 12);
            Size sSmall5 = new Size(5, 12);

            doInitialisation_TextRecognition();
            if ((pSize == sSmall4) || (pSize == sSmall5))
            {
                charQuater q2  = new charQuater(pic.getSubPic(0, 0, 4, 6));
                charQuater q3  = new charQuater(pic.getSubPic(0, 6, 4, 6));
                string     q23 = q2.ToString() + q3.ToString();
                if (q23 == "?BWWB?BWWB")
                {
                    return('1');
                }
            }
            else if (pSize == sBig)
            {
                IPicAccess p1 = pic.getSubPic(3, 0, 4, 6);
                charQuater q1 = new charQuater(p1);

                IPicAccess p2 = pic.getSubPic(0, 0, 4, 6);
                charQuater q2 = new charQuater(p2);

                IPicAccess p3 = pic.getSubPic(0, 6, 4, 6);
                charQuater q3 = new charQuater(p3);

                IPicAccess p4 = pic.getSubPic(3, 6, 4, 6);
                charQuater q4 = new charQuater(p4);

                string q14 = q1.ToString() + q2.ToString() + q3.ToString() + q4.ToString();

                Dictionary <string, char> charDir = new Dictionary <string, char>();
                charDir.Add("\\WBWB/BWBW\\WBWB/BWBW", '0');
                charDir.Add("\\WBWB?BWWW?WWBB?WWBB", '2');
                charDir.Add("?WBWW?BWWW?WWBB?WWBB", '2');
                charDir.Add("\\WBWB?BWWW/BWBB?WBBB", '2');
                charDir.Add("?WBBW?BWWB?WWWB/BWBW", '3');
                charDir.Add("/BWBB?WWWB?WWWW?BWWB", '4');
                charDir.Add("?BBWW/BWBW?WWWB/BWBW", '5');
                charDir.Add("?BBBW?BWWB?WBWB/BWBW", '5');
                charDir.Add("?BBBB?BWWB?WBWB/BWBW", '5');
                charDir.Add("?WBWB/BWBW\\WBWB/BWBW", '6');
                charDir.Add("?WBBB/BWBB\\WBWB/BWBW", '6');
                charDir.Add("?WBBW/BWBB\\WBWB/BWBW", '6');
                charDir.Add("/BBBW?BBWB?BWWW?WBWW", '7');
                charDir.Add("?WBBW?BWWB\\WBWB?WWBW", '8');
                charDir.Add("?WBBW?BWWB?BWWB?WBBW", '8');
                charDir.Add("?WBBW?BWWB?WWWB?WWBW", '8');
                charDir.Add("\\WBWB/BWBW?WBWB/BWBW", '9');
                charDir.Add("\\WBWB/BWBW?BBWB/BBBW", '9');
                charDir.Add("\\WBWB/BWBW?BWWB/BBBW", '9');
                charDir.Add("\\WBWB/BWBW?WWWB/BWBW", '9');

                charDir.Add("\\WBWB/BBBW?WBBW?BWWW", 'p');

                if (charDir.ContainsKey(q14))
                {
                    return(charDir[q14]);
                }

                if (q14 == "?WWWW?WWWW?WWWW?WWWW")
                {
                    // no pattern, all corner while
                    if (areWhite(pic, "0.9.1.9.2.9.3.9.3.10.3.11"))
                    {
                        return('4');
                    }
                }

                try
                {
                    pic.getClone().ToFile(
                        "CharUnknown_"
                        + q14
                        .Replace("?", "_F_")
                        .Replace("/", "_SF_")
                        .Replace("\\", "_SB_"));
                }
                catch (SystemException)
                {
                }


                ObjectDetection test  = new ObjectDetection(pic, false, true);
                int             count = 0;
                test.DoDetection(new dOnDetectObject(delegate(ObjectPoints points, IPicAccess originalPic)
                {
                    return(true);
                }), false, 0);
                //test.BiggerstWhite.Rect.Height >
                test = null;
            }

            return('?');
        }