コード例 #1
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);
        }
コード例 #2
0
 public ObjectDetection(IPicAccess pic, bool tryCrossOnWhite, bool tryCrossOnBlack)
 {
     WhiteObjectList      = new List <ObjectPoints>();
     BlackObjectList      = new List <ObjectPoints>();
     this.Pic             = pic;
     this.TryCrossOnWhite = tryCrossOnWhite;
     this.TryCrossOnBlack = tryCrossOnBlack;
 }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        private char getPixelChar(IPicAccess pic4x6, int x, int y)
        {
            switch (pic4x6.getPixel(x, y))
            {
            case PixelInfo.White: return('W');

            case PixelInfo.Black: return('B');

            case PixelInfo.Processed: return('_');
            }
            return('?');
        }
コード例 #6
0
 private static bool areWhite(IPicAccess pic, string str)
 {
     string[] sa = str.Split(new char[] { '.' });
     for (int i = 0; i < sa.Length; i += 2)
     {
         int x = int.Parse(sa[i]);
         int y = int.Parse(sa[i + 1]);
         if (pic.getPixel(x, y) != PixelInfo.White)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #7
0
        public static SpecificResult_Text DetectText(MyPic mPic, bool debug = false, int minSize = 0)
        {
            SpecificResult_Text r  = new SpecificResult_Text();
            StringBuilder       sb = new StringBuilder();

            try
            {
                DebLog(debug, "New");
                MyPic mClone = (MyPic)mPic.getClone();
                mClone.Threshold_AlmostBlack();
                bool first = true;
                mClone.ToFileIfConfigured("TextRecognitionLibrary.DetectText.SaveInput");

                ObjectDetection od = new ObjectDetection(mClone, true, true);
                int             id = 0;
                od.DoDetection(new dOnDetectObject(delegate(ObjectPoints points, IPicAccess originalPic)
                {
                    id++;
                    string cnfDumpAll = ConfigurationManager.AppSettings["TextRecognitionLibrary.DetectText.DumpAll"];
                    if ((cnfDumpAll != null) && (Boolean.Parse(cnfDumpAll)))
                    {
                        MyPic picDumpAll = (MyPic)ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                        picDumpAll.ToFile(id.ToString());
                    }

                    DebLog(debug, $"id{id} {points.Rect.Height}x{points.Rect.Width} soFar{sb}");

                    if (points.Rect.Height == 10)
                    {
                        MyPic pic10 = (MyPic)ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                        char c      = TextCourierNew10.RecogniseChar(pic10);
                        sb.Append(c);
                        if (first)
                        {
                            first     = false;
                            r.TextPos = points.Points[0];
                        }
                    }
                    else if (points.Rect.Height == 11)
                    {
                        MyPic pic11 = (MyPic)ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                        char c      = TextCourierNew11.RecogniseChar(pic11);
                        sb.Append(c);
                        if (first)
                        {
                            first     = false;
                            r.TextPos = points.Points[0];
                        }
                    }
                    else if (points.Rect.Height == 12)
                    {
                        ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic).ToFile("a12");
                        if ((points.Rect.Width == 4) || (points.Rect.Width == 5) || (points.Rect.Width == 7))
                        {
                            IPicAccess pchar = ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                            IPicAccess pbu   = pchar.getClone();
                            char c           = TextRecognition.RecogniseChar(pchar);
                            sb.Append(c);
                            if (first)
                            {
                                first     = false;
                                r.TextPos = points.Points[0];
                            }
                        }
                        else if (points.Rect.Width == 8)
                        {
                            IPicAccess pchar =
                                ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic)
                                .getSubPic(1, 0, 7, 12);
                            IPicAccess pbu = pchar.getClone();
                            char c         = TextRecognition.RecogniseChar(pchar);
                            sb.Append(c);
                            if (first)
                            {
                                first     = false;
                                r.TextPos = points.Points[0];
                            }
                        }
                        else
                        {
                            // could this be 2 or more chars together?
                            ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic).ToFile("subAll");
                            int x = 0;
                            while (x < points.Rect.Width)
                            {
                                IPicAccess sub = mPic.getSubPic(points.Rect.X + x, points.Rect.Y, 7, 12);
                                sub.ToFile("subtogether");
                                char c = TextRecognition.RecogniseChar(sub.getClone());
                                if (c == '?')
                                {
                                    // not recognised
                                    x = points.Rect.Width;
                                }
                                else
                                {
                                    x += 9;
                                    sb.Append(c);
                                    if (first)
                                    {
                                        first     = false;
                                        r.TextPos = points.Points[0];
                                    }
                                }
                            }
                        }
                    }
                    return(true);
                }), debug, minSize);
                r.Text = sb.ToString();
                return(r);
            }
            catch (Exception ex)
            {
                DebLog(debug, "Exception");
                DebLog(debug, ex.Message);
                if (sb.ToString().Length > 0)
                {
                    r.Text = sb.ToString();
                    return(r);
                }
                var err = new SpecificResult_Text();
                err.Text    = "Exception: " + ex.Message;
                err.TextPos = new Point(0, 0);
                return(err);
            }
        }
コード例 #8
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('?');
        }