From 60791da2ed564322028d609ee967128d2277cf42 Mon Sep 17 00:00:00 2001 From: Max Hedge Date: Sat, 10 Jan 2015 17:24:40 +0000 Subject: [PATCH] v1.6 * Add new OCR Corrections form ("Edit" button on Corrections tab) --- RegulatedNoise/EditOcrResults.Designer.cs | 184 ++++++++++++++++++ RegulatedNoise/EditOcrResults.cs | 94 +++++++++ RegulatedNoise/EditOcrResults.resx | 120 ++++++++++++ .../ScreenshotResults.cs | 1 + RegulatedNoise/Form1.Designer.cs | 43 ++-- RegulatedNoise/Form1.cs | 36 +++- RegulatedNoise/Form1.resx | 6 +- RegulatedNoise/Ocr.cs | 12 +- RegulatedNoise/RegulatedNoise.csproj | 9 + 9 files changed, 477 insertions(+), 28 deletions(-) create mode 100644 RegulatedNoise/EditOcrResults.Designer.cs create mode 100644 RegulatedNoise/EditOcrResults.cs create mode 100644 RegulatedNoise/EditOcrResults.resx diff --git a/RegulatedNoise/EditOcrResults.Designer.cs b/RegulatedNoise/EditOcrResults.Designer.cs new file mode 100644 index 0000000..2907903 --- /dev/null +++ b/RegulatedNoise/EditOcrResults.Designer.cs @@ -0,0 +1,184 @@ +namespace RegulatedNoise +{ + partial class EditOcrResults + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lbEditOcrResults = new System.Windows.Forms.ListBox(); + this.pbEditOcrResultsOriginalImage = new System.Windows.Forms.PictureBox(); + this.tbEditOcrResultsCommodityName = new System.Windows.Forms.TextBox(); + this.tbEditOcrResultsSellPrice = new System.Windows.Forms.TextBox(); + this.tbEditOcrResultsBuyPrice = new System.Windows.Forms.TextBox(); + this.tbEditOcrResultsDemand = new System.Windows.Forms.TextBox(); + this.tbEditOcrResultsDemandLevel = new System.Windows.Forms.TextBox(); + this.tbEditOcrResultsSupplyLevel = new System.Windows.Forms.TextBox(); + this.tbEditOcrResultsSupply = new System.Windows.Forms.TextBox(); + this.bEditOcrResultsOK = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pbEditOcrResultsOriginalImage)).BeginInit(); + this.SuspendLayout(); + // + // lbEditOcrResults + // + this.lbEditOcrResults.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbEditOcrResults.FormattingEnabled = true; + this.lbEditOcrResults.Location = new System.Drawing.Point(9, 9); + this.lbEditOcrResults.Name = "lbEditOcrResults"; + this.lbEditOcrResults.ScrollAlwaysVisible = true; + this.lbEditOcrResults.Size = new System.Drawing.Size(1058, 160); + this.lbEditOcrResults.TabIndex = 0; + this.lbEditOcrResults.SelectedIndexChanged += new System.EventHandler(this.lbEditOcrResults_SelectedIndexChanged); + // + // pbEditOcrResultsOriginalImage + // + this.pbEditOcrResultsOriginalImage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pbEditOcrResultsOriginalImage.Location = new System.Drawing.Point(12, 175); + this.pbEditOcrResultsOriginalImage.Name = "pbEditOcrResultsOriginalImage"; + this.pbEditOcrResultsOriginalImage.Size = new System.Drawing.Size(1055, 29); + this.pbEditOcrResultsOriginalImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pbEditOcrResultsOriginalImage.TabIndex = 1; + this.pbEditOcrResultsOriginalImage.TabStop = false; + // + // tbEditOcrResultsCommodityName + // + this.tbEditOcrResultsCommodityName.Font = new System.Drawing.Font("Arial Narrow", 17.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbEditOcrResultsCommodityName.Location = new System.Drawing.Point(62, 210); + this.tbEditOcrResultsCommodityName.Name = "tbEditOcrResultsCommodityName"; + this.tbEditOcrResultsCommodityName.Size = new System.Drawing.Size(315, 34); + this.tbEditOcrResultsCommodityName.TabIndex = 2; + this.tbEditOcrResultsCommodityName.TextChanged += new System.EventHandler(this.tbEditOcrResultTextChanged); + // + // tbEditOcrResultsSellPrice + // + this.tbEditOcrResultsSellPrice.Font = new System.Drawing.Font("Arial", 17.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbEditOcrResultsSellPrice.Location = new System.Drawing.Point(383, 210); + this.tbEditOcrResultsSellPrice.Name = "tbEditOcrResultsSellPrice"; + this.tbEditOcrResultsSellPrice.Size = new System.Drawing.Size(100, 34); + this.tbEditOcrResultsSellPrice.TabIndex = 3; + this.tbEditOcrResultsSellPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.tbEditOcrResultsSellPrice.TextChanged += new System.EventHandler(this.tbEditOcrResultTextChanged); + // + // tbEditOcrResultsBuyPrice + // + this.tbEditOcrResultsBuyPrice.Font = new System.Drawing.Font("Arial", 17.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbEditOcrResultsBuyPrice.Location = new System.Drawing.Point(489, 210); + this.tbEditOcrResultsBuyPrice.Name = "tbEditOcrResultsBuyPrice"; + this.tbEditOcrResultsBuyPrice.Size = new System.Drawing.Size(82, 34); + this.tbEditOcrResultsBuyPrice.TabIndex = 4; + this.tbEditOcrResultsBuyPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.tbEditOcrResultsBuyPrice.TextChanged += new System.EventHandler(this.tbEditOcrResultTextChanged); + // + // tbEditOcrResultsDemand + // + this.tbEditOcrResultsDemand.Font = new System.Drawing.Font("Arial", 17.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbEditOcrResultsDemand.Location = new System.Drawing.Point(650, 210); + this.tbEditOcrResultsDemand.Name = "tbEditOcrResultsDemand"; + this.tbEditOcrResultsDemand.Size = new System.Drawing.Size(133, 34); + this.tbEditOcrResultsDemand.TabIndex = 5; + this.tbEditOcrResultsDemand.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.tbEditOcrResultsDemand.TextChanged += new System.EventHandler(this.tbEditOcrResultTextChanged); + // + // tbEditOcrResultsDemandLevel + // + this.tbEditOcrResultsDemandLevel.Font = new System.Drawing.Font("Arial Narrow", 17.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbEditOcrResultsDemandLevel.Location = new System.Drawing.Point(786, 210); + this.tbEditOcrResultsDemandLevel.Name = "tbEditOcrResultsDemandLevel"; + this.tbEditOcrResultsDemandLevel.Size = new System.Drawing.Size(57, 34); + this.tbEditOcrResultsDemandLevel.TabIndex = 6; + this.tbEditOcrResultsDemandLevel.TextChanged += new System.EventHandler(this.tbEditOcrResultTextChanged); + // + // tbEditOcrResultsSupplyLevel + // + this.tbEditOcrResultsSupplyLevel.Font = new System.Drawing.Font("Arial Narrow", 17.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbEditOcrResultsSupplyLevel.Location = new System.Drawing.Point(977, 210); + this.tbEditOcrResultsSupplyLevel.Name = "tbEditOcrResultsSupplyLevel"; + this.tbEditOcrResultsSupplyLevel.Size = new System.Drawing.Size(57, 34); + this.tbEditOcrResultsSupplyLevel.TabIndex = 8; + this.tbEditOcrResultsSupplyLevel.TextChanged += new System.EventHandler(this.tbEditOcrResultTextChanged); + // + // tbEditOcrResultsSupply + // + this.tbEditOcrResultsSupply.Font = new System.Drawing.Font("Arial", 17.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbEditOcrResultsSupply.Location = new System.Drawing.Point(849, 210); + this.tbEditOcrResultsSupply.Name = "tbEditOcrResultsSupply"; + this.tbEditOcrResultsSupply.Size = new System.Drawing.Size(125, 34); + this.tbEditOcrResultsSupply.TabIndex = 7; + this.tbEditOcrResultsSupply.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.tbEditOcrResultsSupply.TextChanged += new System.EventHandler(this.tbEditOcrResultTextChanged); + // + // bEditOcrResultsOK + // + this.bEditOcrResultsOK.Location = new System.Drawing.Point(929, 250); + this.bEditOcrResultsOK.Name = "bEditOcrResultsOK"; + this.bEditOcrResultsOK.Size = new System.Drawing.Size(138, 26); + this.bEditOcrResultsOK.TabIndex = 9; + this.bEditOcrResultsOK.Text = "OK"; + this.bEditOcrResultsOK.UseVisualStyleBackColor = true; + this.bEditOcrResultsOK.Click += new System.EventHandler(this.bEditOcrResultsOK_Click); + // + // EditOcrResults + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1079, 286); + this.Controls.Add(this.bEditOcrResultsOK); + this.Controls.Add(this.tbEditOcrResultsSupplyLevel); + this.Controls.Add(this.tbEditOcrResultsSupply); + this.Controls.Add(this.tbEditOcrResultsDemandLevel); + this.Controls.Add(this.tbEditOcrResultsDemand); + this.Controls.Add(this.tbEditOcrResultsBuyPrice); + this.Controls.Add(this.tbEditOcrResultsSellPrice); + this.Controls.Add(this.tbEditOcrResultsCommodityName); + this.Controls.Add(this.pbEditOcrResultsOriginalImage); + this.Controls.Add(this.lbEditOcrResults); + this.MaximumSize = new System.Drawing.Size(1095, 538); + this.MinimumSize = new System.Drawing.Size(1095, 39); + this.Name = "EditOcrResults"; + this.Text = "EditOcrResults"; + ((System.ComponentModel.ISupportInitialize)(this.pbEditOcrResultsOriginalImage)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListBox lbEditOcrResults; + private System.Windows.Forms.PictureBox pbEditOcrResultsOriginalImage; + private System.Windows.Forms.TextBox tbEditOcrResultsCommodityName; + private System.Windows.Forms.TextBox tbEditOcrResultsSellPrice; + private System.Windows.Forms.TextBox tbEditOcrResultsBuyPrice; + private System.Windows.Forms.TextBox tbEditOcrResultsDemand; + private System.Windows.Forms.TextBox tbEditOcrResultsDemandLevel; + private System.Windows.Forms.TextBox tbEditOcrResultsSupplyLevel; + private System.Windows.Forms.TextBox tbEditOcrResultsSupply; + private System.Windows.Forms.Button bEditOcrResultsOK; + } +} \ No newline at end of file diff --git a/RegulatedNoise/EditOcrResults.cs b/RegulatedNoise/EditOcrResults.cs new file mode 100644 index 0000000..e37c5f2 --- /dev/null +++ b/RegulatedNoise/EditOcrResults.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Microsoft.SqlServer.Server; + +namespace RegulatedNoise +{ + public partial class EditOcrResults : Form + { + private string _startOfRow, _endOfRow; + public string ReturnValue; + + public EditOcrResults(string dataToEdit) + { + InitializeComponent(); + lbEditOcrResults.Items.Clear(); + + var rows = dataToEdit.Split(new string[] {"\r\n"}, StringSplitOptions.None); + + foreach (var row in rows) + { + if(row.Contains(';')) + lbEditOcrResults.Items.Add(row); + } + } + + private bool suspendTextChanged = false; + + private void lbEditOcrResults_SelectedIndexChanged(object sender, EventArgs e) + { + suspendTextChanged = true; + var row = lbEditOcrResults.Text; + var rowId = row.Substring(row.LastIndexOf(";", System.StringComparison.Ordinal)+1); + + if (pbEditOcrResultsOriginalImage.Image != null) + pbEditOcrResultsOriginalImage.Image.Dispose(); + + if (File.Exists(".//OCR Correction Images//" + rowId + ".png")) + pbEditOcrResultsOriginalImage.Image = Bitmap.FromFile(".//OCR Correction Images//" + rowId + ".png"); + + var results = row.Split(';'); + if (results.GetLength(0) > 7) + { + tbEditOcrResultsCommodityName.Text = results[2]; + tbEditOcrResultsSellPrice.Text = results[3]; + tbEditOcrResultsBuyPrice.Text = results[4]; + tbEditOcrResultsDemand.Text = results[5]; + tbEditOcrResultsDemandLevel.Text = results[6]; + tbEditOcrResultsSupply.Text = results[7]; + tbEditOcrResultsSupplyLevel.Text = results[8]; + _startOfRow = results[0] + ";" + results[1] + ";"; + _endOfRow = results[9]+";"+results[10]+";"+results[11]; + } + suspendTextChanged = false; + + } + + private void tbEditOcrResultTextChanged(object sender, EventArgs e) + { + if (suspendTextChanged) return; + + lbEditOcrResults.SelectedIndexChanged -= lbEditOcrResults_SelectedIndexChanged; + lbEditOcrResults.Items[lbEditOcrResults.SelectedIndex] = _startOfRow + + tbEditOcrResultsCommodityName.Text + ";" + + tbEditOcrResultsSellPrice.Text + ";" + + tbEditOcrResultsBuyPrice.Text + ";" + + tbEditOcrResultsDemand.Text + ";" + + tbEditOcrResultsDemandLevel.Text + ";" + + tbEditOcrResultsSupply.Text + ";" + + tbEditOcrResultsSupplyLevel.Text + ";" + + _endOfRow + ; + + lbEditOcrResults.SelectedIndexChanged += lbEditOcrResults_SelectedIndexChanged; + } + + private void bEditOcrResultsOK_Click(object sender, EventArgs e) + { + foreach (var x in lbEditOcrResults.Items) + { + ReturnValue += x + "\r\n"; + } + DialogResult= DialogResult.OK; + Close(); + } + } +} diff --git a/RegulatedNoise/EditOcrResults.resx b/RegulatedNoise/EditOcrResults.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RegulatedNoise/EditOcrResults.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RegulatedNoise/Enums and Utility Classes/ScreenshotResults.cs b/RegulatedNoise/Enums and Utility Classes/ScreenshotResults.cs index a49f379..b9fa73d 100644 --- a/RegulatedNoise/Enums and Utility Classes/ScreenshotResults.cs +++ b/RegulatedNoise/Enums and Utility Classes/ScreenshotResults.cs @@ -8,5 +8,6 @@ public class ScreeenshotResults public Bitmap[,] originalBitmaps; public float[,] originalBitmapConfidences; public string screenshotName; + public string[] rowIds; } } diff --git a/RegulatedNoise/Form1.Designer.cs b/RegulatedNoise/Form1.Designer.cs index 697ca25..2d45501 100644 --- a/RegulatedNoise/Form1.Designer.cs +++ b/RegulatedNoise/Form1.Designer.cs @@ -81,7 +81,6 @@ private void InitializeComponent() this.label9 = new System.Windows.Forms.Label(); this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.tabPage1 = new System.Windows.Forms.TabPage(); - this.lblLightYearsFromCurrentSystem = new System.Windows.Forms.Label(); this.bShowStationAtStarchartDotInfo = new System.Windows.Forms.Button(); this.bStationDeleteRow = new System.Windows.Forms.Button(); this.bStationEditRow = new System.Windows.Forms.Button(); @@ -89,6 +88,7 @@ private void InitializeComponent() this.tbStationRename = new System.Windows.Forms.TextBox(); this.tbSystemRename = new System.Windows.Forms.TextBox(); this.button6 = new System.Windows.Forms.Button(); + this.lblLightYearsFromCurrentSystem = new System.Windows.Forms.Label(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.bCommodityDeleteRow = new System.Windows.Forms.Button(); this.bEditCommodity = new System.Windows.Forms.Button(); @@ -154,6 +154,7 @@ private void InitializeComponent() this.tabControl3 = new System.Windows.Forms.TabControl(); this.tabOCR = new System.Windows.Forms.TabPage(); this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.bEditResults = new System.Windows.Forms.Button(); this.cbAutoImport = new System.Windows.Forms.CheckBox(); this.cbUseEddnTestSchema = new System.Windows.Forms.CheckBox(); this.cbDeleteScreenshotOnImport = new System.Windows.Forms.CheckBox(); @@ -803,7 +804,7 @@ private void InitializeComponent() // this.splitContainer1.Panel2.Controls.Add(this.label9); this.splitContainer1.Panel2.Controls.Add(this.chart2); - this.splitContainer1.Size = new System.Drawing.Size(198, 465); + this.splitContainer1.Size = new System.Drawing.Size(192, 465); this.splitContainer1.SplitterDistance = 215; this.splitContainer1.SplitterWidth = 6; this.splitContainer1.TabIndex = 7; @@ -830,7 +831,7 @@ private void InitializeComponent() series5.ChartArea = "ChartArea1"; series5.Name = "Series1"; this.chart1.Series.Add(series5); - this.chart1.Size = new System.Drawing.Size(193, 213); + this.chart1.Size = new System.Drawing.Size(187, 213); this.chart1.TabIndex = 5; this.chart1.Text = "chart1"; this.chart1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseMove); @@ -857,7 +858,7 @@ private void InitializeComponent() series6.ChartArea = "ChartArea1"; series6.Name = "Series1"; this.chart2.Series.Add(series6); - this.chart2.Size = new System.Drawing.Size(188, 173); + this.chart2.Size = new System.Drawing.Size(182, 167); this.chart2.TabIndex = 6; this.chart2.Text = "chart2"; this.chart2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseMove); @@ -880,15 +881,6 @@ private void InitializeComponent() this.tabPage1.Text = "By Station"; this.tabPage1.UseVisualStyleBackColor = true; // - // lblLightYearsFromCurrentSystem - // - this.lblLightYearsFromCurrentSystem.AutoSize = true; - this.lblLightYearsFromCurrentSystem.Location = new System.Drawing.Point(294, 18); - this.lblLightYearsFromCurrentSystem.Name = "lblLightYearsFromCurrentSystem"; - this.lblLightYearsFromCurrentSystem.Size = new System.Drawing.Size(63, 13); - this.lblLightYearsFromCurrentSystem.TabIndex = 15; - this.lblLightYearsFromCurrentSystem.Text = "( light years)"; - // // bShowStationAtStarchartDotInfo // this.bShowStationAtStarchartDotInfo.Image = ((System.Drawing.Image)(resources.GetObject("bShowStationAtStarchartDotInfo.Image"))); @@ -959,6 +951,15 @@ private void InitializeComponent() this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.RenameStation); // + // lblLightYearsFromCurrentSystem + // + this.lblLightYearsFromCurrentSystem.AutoSize = true; + this.lblLightYearsFromCurrentSystem.Location = new System.Drawing.Point(294, 18); + this.lblLightYearsFromCurrentSystem.Name = "lblLightYearsFromCurrentSystem"; + this.lblLightYearsFromCurrentSystem.Size = new System.Drawing.Size(63, 13); + this.lblLightYearsFromCurrentSystem.TabIndex = 15; + this.lblLightYearsFromCurrentSystem.Text = "( light years)"; + // // tabPage2 // this.tabPage2.Controls.Add(this.bCommodityDeleteRow); @@ -1679,6 +1680,7 @@ private void InitializeComponent() // // groupBox4 // + this.groupBox4.Controls.Add(this.bEditResults); this.groupBox4.Controls.Add(this.cbAutoImport); this.groupBox4.Controls.Add(this.cbUseEddnTestSchema); this.groupBox4.Controls.Add(this.cbDeleteScreenshotOnImport); @@ -1707,6 +1709,16 @@ private void InitializeComponent() this.groupBox4.TabStop = false; this.groupBox4.Text = "OCR Corrections"; // + // bEditResults + // + this.bEditResults.Location = new System.Drawing.Point(6, 402); + this.bEditResults.Name = "bEditResults"; + this.bEditResults.Size = new System.Drawing.Size(570, 23); + this.bEditResults.TabIndex = 32; + this.bEditResults.Text = "Edit Results"; + this.bEditResults.UseVisualStyleBackColor = true; + this.bEditResults.Click += new System.EventHandler(this.bEditResults_Click); + // // cbAutoImport // this.cbAutoImport.AutoSize = true; @@ -1865,7 +1877,7 @@ private void InitializeComponent() this.tbFinalOcrOutput.Multiline = true; this.tbFinalOcrOutput.Name = "tbFinalOcrOutput"; this.tbFinalOcrOutput.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.tbFinalOcrOutput.Size = new System.Drawing.Size(571, 245); + this.tbFinalOcrOutput.Size = new System.Drawing.Size(571, 219); this.tbFinalOcrOutput.TabIndex = 15; this.tbFinalOcrOutput.WordWrap = false; // @@ -2467,7 +2479,7 @@ private void InitializeComponent() this.Controls.Add(this.bOpen); this.Name = "Form1"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; - this.Text = "RegulatedNoise v1.41"; + this.Text = "RegulatedNoise v1.6"; this.Load += new System.EventHandler(this.Form_Load); this.tabControl1.ResumeLayout(false); this.tabHelpAndChangeLog.ResumeLayout(false); @@ -2738,6 +2750,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox cbAutoImport; private System.Windows.Forms.LinkLabel linkLabel9; private System.Windows.Forms.Button bPurgeAllEddnData; + private System.Windows.Forms.Button bEditResults; } } diff --git a/RegulatedNoise/Form1.cs b/RegulatedNoise/Form1.cs index 98f62fe..1a704e2 100644 --- a/RegulatedNoise/Form1.cs +++ b/RegulatedNoise/Form1.cs @@ -121,6 +121,9 @@ public Form1() _logger.Log(" - applied settings"); + if (!Directory.Exists(".//OCR Correction Images")) + Directory.CreateDirectory(".//OCR Correction Images"); + _logger.Log("Initialisation complete"); } @@ -1893,46 +1896,48 @@ public void DisplayResults(string s) } } - public delegate void DisplayCommodityResultsDelegate(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string screenshotName); + public delegate void DisplayCommodityResultsDelegate(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string[] rowIds, string screenshotName); int _correctionRow, _correctionColumn; string[,] _commodityTexts; Bitmap[,] _originalBitmaps; float[,] _originalBitmapConfidences; + string[] _rowIds; string _screenshotName; List _screenshotResultsBuffer = new List(); string _csvOutputSoFar; List _commoditiesSoFar = new List(); - public void DisplayCommodityResults(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string screenshotName) + public void DisplayCommodityResults(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string[] rowIds, string screenshotName) { if (InvokeRequired) { - Invoke(new DisplayCommodityResultsDelegate(DisplayCommodityResults), s, originalBitmaps, originalBitmapConfidences, screenshotName); + Invoke(new DisplayCommodityResultsDelegate(DisplayCommodityResults), s, originalBitmaps, originalBitmapConfidences, rowIds, screenshotName); return; } if (_commodityTexts != null && _correctionColumn < _commodityTexts.GetLength(1)) // there is an existing screenshot being processed... { - _screenshotResultsBuffer.Add(new ScreeenshotResults { originalBitmapConfidences = originalBitmapConfidences, originalBitmaps = originalBitmaps, s = s, screenshotName = screenshotName }); + _screenshotResultsBuffer.Add(new ScreeenshotResults { originalBitmapConfidences = originalBitmapConfidences, originalBitmaps = originalBitmaps, s = s, rowIds = rowIds, screenshotName = screenshotName }); ScreenshotsQueued("(" + (_screenshotResultsBuffer.Count + ocr.ScreenshotBuffer.Count + _preOcrBuffer.Count) + " queued)"); return; } if (originalBitmaps.GetLength(0) != 0) - BeginCorrectingScreenshot(s, originalBitmaps, originalBitmapConfidences, screenshotName); + BeginCorrectingScreenshot(s, originalBitmaps, originalBitmapConfidences, rowIds, screenshotName); else tbCommoditiesOcrOutput.Text = "No rows found..."; } - private void BeginCorrectingScreenshot(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string screenshotName) + private void BeginCorrectingScreenshot(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string[] rowIds, string screenshotName) { _commodityTexts = s; _originalBitmaps = originalBitmaps; _originalBitmapConfidences = originalBitmapConfidences; _screenshotName = screenshotName; + _rowIds = rowIds; _correctionColumn = 0; _correctionRow = -1; bContinueOcr.Text = "Continue"; @@ -2076,7 +2081,7 @@ private void ContinueDisplayingResults() if (cbExtendedInfoInCSV.Checked) finalOutput += Path.GetFileName(_screenshotName) + ";"; - finalOutput += "\r\n"; + finalOutput += _rowIds[row]+"\r\n"; } } @@ -2126,7 +2131,7 @@ private void ContinueDisplayingResults() var nextScreenshot = _screenshotResultsBuffer[0]; _screenshotResultsBuffer.Remove(nextScreenshot); ScreenshotsQueued("(" + (_screenshotResultsBuffer.Count + ocr.ScreenshotBuffer.Count + _preOcrBuffer.Count) + " queued)"); - BeginCorrectingScreenshot(nextScreenshot.s, nextScreenshot.originalBitmaps, nextScreenshot.originalBitmapConfidences, nextScreenshot.screenshotName); + BeginCorrectingScreenshot(nextScreenshot.s, nextScreenshot.originalBitmaps, nextScreenshot.originalBitmapConfidences, nextScreenshot.rowIds, nextScreenshot.screenshotName); } } } @@ -2794,11 +2799,11 @@ private void PostJsonToEddn(CsvRow rowToPost) if (RegulatedNoiseSettings.UseEddnTestSchema) { - json = @"{""$schemaRef"": ""http://schemas.elite-markets.net/eddn/commodity/1/test"",""header"": {""uploaderID"": ""$0$"",""softwareName"": ""RegulatedNoise"",""softwareVersion"": ""v1.5""},""message"": {""buyPrice"": $2$,""timestamp"": ""$3$"",""stationStock"": $4$,""stationName"": ""$5$"",""systemName"": ""$6$"",""demand"": $7$,""sellPrice"": $8$,""itemName"": ""$9$""}}"; + json = @"{""$schemaRef"": ""http://schemas.elite-markets.net/eddn/commodity/1/test"",""header"": {""uploaderID"": ""$0$"",""softwareName"": ""RegulatedNoise"",""softwareVersion"": ""v1.6""},""message"": {""buyPrice"": $2$,""timestamp"": ""$3$"",""stationStock"": $4$,""stationName"": ""$5$"",""systemName"": ""$6$"",""demand"": $7$,""sellPrice"": $8$,""itemName"": ""$9$""}}"; } else { - json = @"{""$schemaRef"": ""http://schemas.elite-markets.net/eddn/commodity/1"",""header"": {""uploaderID"": ""$0$"",""softwareName"": ""RegulatedNoise"",""softwareVersion"": ""v1.5""},""message"": {""buyPrice"": $2$,""timestamp"": ""$3$"",""stationStock"": $4$,""stationName"": ""$5$"",""systemName"": ""$6$"",""demand"": $7$,""sellPrice"": $8$,""itemName"": ""$9$""}}"; + json = @"{""$schemaRef"": ""http://schemas.elite-markets.net/eddn/commodity/1"",""header"": {""uploaderID"": ""$0$"",""softwareName"": ""RegulatedNoise"",""softwareVersion"": ""v1.6""},""message"": {""buyPrice"": $2$,""timestamp"": ""$3$"",""stationStock"": $4$,""stationName"": ""$5$"",""systemName"": ""$6$"",""demand"": $7$,""sellPrice"": $8$,""itemName"": ""$9$""}}"; } @@ -3543,6 +3548,17 @@ private static Dictionary> PurgeEDDNFromDirectory(Dictionar return newDirectory; } + private void bEditResults_Click(object sender, EventArgs e) + { + var f = new EditOcrResults(tbFinalOcrOutput.Text); + var q = f.ShowDialog(); + + if (q == DialogResult.OK) + { + tbFinalOcrOutput.Text = f.ReturnValue; + } + } + // diff --git a/RegulatedNoise/Form1.resx b/RegulatedNoise/Form1.resx index eb85da1..3e4968c 100644 --- a/RegulatedNoise/Form1.resx +++ b/RegulatedNoise/Form1.resx @@ -1499,7 +1499,10 @@ - v1.5 + v1.6 +* Add new OCR Corrections form ("Edit" button on Corrections tab) + +v1.5 * add Maddavo's stations data (static copy) to auto-fix station name OCR errors (thanks to Maddavo) - this also gives us pad-size information, but not using that yet * Move a bunch of code to make Form1.cs a less-depressing place to be * Add an auto-import checkbox and setting - this defaults to Off at the moment @@ -1507,6 +1510,7 @@ * Remove improbable punctuation from station names (but not apostrophes...) * Data imported from EDDN now has "<From EDDN>" as the "Screenshot Name" * He Suits is now H.E. Suits... also added Resonating Separators to the hard-coded list of commodity names + v1.41 * Fix Transaction credits does not accept numbers >100 (GitHub issue #1) diff --git a/RegulatedNoise/Ocr.cs b/RegulatedNoise/Ocr.cs index e1bd717..2492e09 100644 --- a/RegulatedNoise/Ocr.cs +++ b/RegulatedNoise/Ocr.cs @@ -249,6 +249,7 @@ public void PerformOcr(List> textRowLocations) var commodityColumnText = new string[textRowLocations.Count(), 8]; ; var originalBitmaps = new Bitmap[textRowLocations.Count(),8]; var originalBitmapConfidences = new float[textRowLocations.Count(), 8]; + var rowIds = new string[textRowLocations.Count()]; var rowCtr = 0; @@ -264,6 +265,13 @@ public void PerformOcr(List> textRowLocations) if (startRow < 0) startRow = 0; if (heightRow + startRow > bTrimmedContrast.Height) heightRow = bTrimmedContrast.Height - startRow; + // We'll use this later to identify the right correction image + rowIds[rowCtr] = Guid.NewGuid().ToString(); + using (Bitmap b = Crop(bTrimmedContrast, new Rectangle(0, startRow, bTrimmedContrast.Width, heightRow))) + { + b.Save(".//OCR Correction Images//" + rowIds[rowCtr] + ".png"); + } + int columnCounter = 0; while (columnCounter < 8) { @@ -298,7 +306,7 @@ public void PerformOcr(List> textRowLocations) left = 0; width = _calibrationPoints[3].X - _calibrationPoints[2].X; break; } - var fudgeFactor = _bOriginal.Height*6/1440; + var fudgeFactor = 0;// _bOriginal.Height * 6 / 1440; left = left + fudgeFactor; width = width - fudgeFactor; @@ -429,7 +437,7 @@ public void PerformOcr(List> textRowLocations) _bOriginal.Dispose(); _bOriginalClone.Dispose(); // Send the results for this screenshot back to the Form - _callingForm.DisplayCommodityResults(commodityColumnText, originalBitmaps, originalBitmapConfidences, CurrentScreenshot); + _callingForm.DisplayCommodityResults(commodityColumnText, originalBitmaps, originalBitmapConfidences, rowIds, CurrentScreenshot); // ...and if we've got any buffered screenshots waiting to be processed, process the next one if (ScreenshotBuffer.Count > 0) diff --git a/RegulatedNoise/RegulatedNoise.csproj b/RegulatedNoise/RegulatedNoise.csproj index a215f7c..c68b4f7 100644 --- a/RegulatedNoise/RegulatedNoise.csproj +++ b/RegulatedNoise/RegulatedNoise.csproj @@ -54,6 +54,12 @@ + + Form + + + EditOcrResults.cs + Form @@ -94,6 +100,9 @@ + + EditOcrResults.cs + EditPriceData.cs