예제 #1
0
 public CellHint(CellHintType t, CellHintArea a, int n, double ocrd)
 {
     Number      = n;
     Area        = a;
     Type        = t;
     OCRDistance = ocrd;
 }
예제 #2
0
 public CellHint(CellHintType t, CellHintArea a, int n, double ocrd, string adv)
 {
     Number          = n;
     Area            = a;
     Type            = t;
     OCRDistance     = ocrd;
     AltDisplayValue = adv;
 }
예제 #3
0
        private CellHint GetHexagonHint()
        {
            if (Type == HexagonType.HIDDEN || Type == HexagonType.UNKNOWN)
            {
                return(new CellHint());
            }

            if (Type == HexagonType.INACTIVE)
            {
                int    activePixel;
                Bitmap img = GetProcessedImage(false, out activePixel);

                if (activePixel == 0)
                {
                    return(new CellHint());
                }

                double errDistance;
                var    txt = PatternOCR.Recognize(img, OCRCoupling.NORMAL_COUPLED_SEGMENTS, out errDistance);

                StaticDebugSettings.ImageSave(img, txt);

                if (Regex.IsMatch(txt, @"^\{[0-9]+\}$"))
                {
                    return(new CellHint(CellHintType.CONSECUTIVE, CellHintArea.DIRECT, int.Parse(txt.Substring(1, txt.Length - 2)), errDistance));
                }
                if (Regex.IsMatch(txt, @"^-[0-9]+-$"))
                {
                    return(new CellHint(CellHintType.NONCONSECUTIVE, CellHintArea.DIRECT, int.Parse(txt.Substring(1, txt.Length - 2)), errDistance));
                }
                if (Regex.IsMatch(txt, @"^[0-9]+$"))
                {
                    return(new CellHint(CellHintType.COUNT, CellHintArea.DIRECT, int.Parse(txt), errDistance));
                }
                if (txt == "?")
                {
                    return(new CellHint());
                }

                if (Regex.IsMatch(txt, @"^[0-9]+-$"))                 // special case (pOCR fail)
                {
                    return(new CellHint(CellHintType.NONCONSECUTIVE, CellHintArea.DIRECT, int.Parse(txt.Substring(0, txt.Length - 1)), errDistance));
                }
                if (Regex.IsMatch(txt, @"^-[0-9]+$"))                 // special case (pOCR fail)
                {
                    return(new CellHint(CellHintType.NONCONSECUTIVE, CellHintArea.DIRECT, int.Parse(txt.Substring(1, txt.Length - 1)), errDistance));
                }

                throw new Exception("OCR failed (" + txt + ") :> " + errDistance);
            }

            if (Type == HexagonType.ACTIVE)
            {
                int    activePixel;
                Bitmap img = GetProcessedImage(false, out activePixel);

                if (activePixel == 0)
                {
                    return(new CellHint());
                }

                double errDistance;
                var    txt = PatternOCR.Recognize(img, OCRCoupling.NORMAL_COUPLED_SEGMENTS, out errDistance);

                StaticDebugSettings.ImageSave(img, txt);

                if (Regex.IsMatch(txt, @"^[0-9]+$"))
                {
                    return(new CellHint(CellHintType.COUNT, CellHintArea.CIRCLE, int.Parse(txt), errDistance));
                }

                throw new Exception("OCR failed (" + txt + ") :> " + errDistance);
            }

            if (Type == HexagonType.NOCELL)
            {
                int    activePixel;
                Bitmap img = GetProcessedImage(false, out activePixel);
                if (activePixel == 0)
                {
                    return(new CellHint());
                }

                CellHintArea col = GetHintColumn(img);

                if (col == CellHintArea.NONE)
                {
                    throw new Exception("OCR failed (Can't find column)");
                }

                if (col == CellHintArea.COLUMN_LEFT)
                {
                    img = RotateImage(img, -60, Color.White);
                }
                else if (col == CellHintArea.COLUMN_RIGHT)
                {
                    img = RotateImage(img, +60, Color.White);
                }

                double errDistance;
                var    txt = PatternOCR.Recognize(img, OCRCoupling.NORMAL_COUPLED_SEGMENTS, out errDistance);

                StaticDebugSettings.ImageSave(img, txt);

                if (Regex.IsMatch(txt, @"^\{[0-9]+\}$"))
                {
                    return(new CellHint(CellHintType.CONSECUTIVE, col, int.Parse(txt.Substring(1, txt.Length - 2)), errDistance));
                }
                if (Regex.IsMatch(txt, @"^-[0-9]+-$"))
                {
                    return(new CellHint(CellHintType.NONCONSECUTIVE, col, int.Parse(txt.Substring(1, txt.Length - 2)), errDistance));
                }
                if (Regex.IsMatch(txt, @"^[0-9]+$"))
                {
                    return(new CellHint(CellHintType.COUNT, col, int.Parse(txt), errDistance));
                }

                if (Regex.IsMatch(txt, @"^[0-9]+-$"))                 // special case (pOCR fail)
                {
                    return(new CellHint(CellHintType.NONCONSECUTIVE, col, int.Parse(txt.Substring(0, txt.Length - 1)), errDistance));
                }
                if (Regex.IsMatch(txt, @"^-[0-9]+$"))                 // special case (pOCR fail)
                {
                    return(new CellHint(CellHintType.NONCONSECUTIVE, col, int.Parse(txt.Substring(1, txt.Length - 1)), errDistance));
                }

                throw new Exception("OCR failed (" + txt + ") :> " + errDistance);
            }

            throw new Exception("WTF - Type ==" + Type);
        }