private void CopyData() { if (cell1.HasValue && cell2.HasValue && currentTable.NonEmpty()) { Point c1 = cell1.Value; Point c2 = cell2.Value; int minY = Math.Min(c1.Y, c2.Y); int maxY = Math.Max(c1.Y, c2.Y); int minX = Math.Min(c1.X, c2.X); int maxX = Math.Max(c1.X, c2.X); string str = ""; Bitmap currentImage = new Bitmap(originalImage); Graphics g = Graphics.FromImage(currentImage); currentTable.ForEach(table => { table.DrawTable(g, new Pen(Color.Red, 2)); Brush recognitionBrush = new SolidBrush(Color.FromArgb(50, Color.Green)); Brush unsureBrush = new SolidBrush(Color.FromArgb(50, Color.Yellow)); Brush noneBrush = new SolidBrush(Color.FromArgb(50, Color.Red)); int cellCount = (maxY - minY + 1) * (maxX - minX + 1); ProgressDialogs.WithProgress(cellCount, ph => { for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { table.GetCellImage(originalImage, x, y).ForEach(cellImage => { Option <GradeDigest> digestOpt = GradeOCR.Program.GetGradeDigest(cellImage); digestOpt.ForEach(gd => { RecognitionResult res = GradeOCR.Program.RecognizeGrade(gd); str += res.Grade; if (res.Confident) { g.FillPath(recognitionBrush, table.GetCellContour(x, y).Get()); } else { g.FillPath(unsureBrush, table.GetCellContour(x, y).Get()); } }); if (digestOpt.IsEmpty()) { g.FillPath(unsureBrush, table.GetCellContour(x, y).Get()); } }); str += "\t"; ph.Increment(); } str += "\n"; } }); }); g.Dispose(); registerPV.SetImageKeepZoom(currentImage); str = str.Substring(0, str.Length - 1); // trim last newline Clipboard.SetText(str); } }
public RegisterViewForm() { InitializeComponent(); registerPV = PictureView.InsertIntoPanel(registerPanel); this.Shown += new EventHandler(delegate { ProcessNextImage(); }); this.nextRegisterButton.Click += new EventHandler(delegate { MoveImageToDone(currentFileName); ProcessNextImage(); }); Point?selectionStart = null; this.registerPV.AddDoubleClickListener((pt, e) => { Util.NewThread(() => { currentTable.ForEach(table => { if (e.Button == MouseButtons.Left) { table.GetCellAtPoint(pt.X, pt.Y).ForEach(cell => { nextImageIndex = null; ProcessTableCell(cell.X, cell.Y); // color processed cell with green table.GetCellContour(cell.X, cell.Y).ForEach(cellPath => { Graphics g = Graphics.FromImage(currentImage); g.FillPath(new SolidBrush(Color.FromArgb(100, Color.Green)), cellPath); g.Dispose(); }); registerPV.SetImageKeepZoom(currentImage); }); } else if (e.Button == MouseButtons.Right) { table.GetCellAtPoint(pt.X, pt.Y).ForEach(cell => { if (selectionStart.HasValue) { Graphics g = Graphics.FromImage(currentImage); int minX = Math.Min(selectionStart.Value.X, cell.X); int maxX = Math.Max(selectionStart.Value.X, cell.X); int minY = Math.Min(selectionStart.Value.Y, cell.Y); int maxY = Math.Max(selectionStart.Value.Y, cell.Y); nextImageIndex = null; ProgressDialogs.WithProgress((maxX - minX + 1) * (maxY - minY + 1), pd => { for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { ProcessTableCell(x, y); table.GetCellContour(x, y).ForEach(cellPath => { g.FillPath(new SolidBrush(Color.FromArgb(100, Color.Green)), cellPath); }); pd.Increment(); } } }); // color processed cells with green g.Dispose(); registerPV.SetImageKeepZoom(currentImage); selectionStart = null; } else { selectionStart = new Point(cell.X, cell.Y); } }); } }); }); }); this.debugOcrButton.Click += new EventHandler(delegate { (new TableRecognitionDebugView(origImage)).ShowDialog(); }); }