private void OnCleanImageSave(object sender, RoutedEventArgs eargs) { try { int cleaned = StaticDebugSettings.CleanImageSave(); MessageBox.Show(cleaned + " images due to redundancy removed"); } catch (Exception e) { MessageBox.Show(e.ToString(), "Execption while executing", MessageBoxButton.OK, MessageBoxImage.Error); } }
private CounterValue GetCounterValue() { double errDistance; int activepixel; var img = GetProcessedImage(false, out activepixel); var txt = patternOCR.Recognize(img, OCRCoupling.HIGH_COUPLED_SEGMENTS, out errDistance); StaticDebugSettings.ImageSave(img, txt); int value = int.Parse(txt); return(new CounterValue(value, errDistance)); }
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); }