Skip to content

Commit

Permalink
- Fixed #2 image file filter is applied, exception handling on image …
Browse files Browse the repository at this point in the history
…file loading.

- Removed redundant declarations in OCRResult, added a base class OCRDimBase
  • Loading branch information
MrFlapstaart committed Aug 12, 2022
1 parent 9253b7c commit fdb8a8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 82 deletions.
3 changes: 2 additions & 1 deletion MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,21 @@ private void button1_Click(object sender, EventArgs e)
return;

Logger.Start();
Logger.AddLog("Opening file");
Image testimage = Bitmap.FromFile(imageOpenDialog.FileName);
Bitmap bitmap = new Bitmap(testimage);
Logger.AddLog("Opening file");
try
{
Image testimage = Bitmap.FromFile(imageOpenDialog.FileName);
Bitmap bitmap = new Bitmap(testimage);
ProcessImage(bitmap);
}
catch
{
Logger.AddLog($"Error opening image file");
logBox.Text = Logger.Finish();
MessageBox.Show("This is not a valid image file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

ProcessImage(bitmap);

}

private void ProcessImage(Bitmap bitmap)
Expand Down
93 changes: 16 additions & 77 deletions OCRResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

namespace GameOCRTTS
{
[XmlRoot(ElementName = "String")]
public class String
{
public class OCRDimBase
{
[XmlAttribute(AttributeName = "ID")]
public string Id { get; set; }

Expand All @@ -25,6 +24,11 @@ public class String
[XmlAttribute(AttributeName = "HEIGHT")]
public string Height { get; set; }

}

[XmlRoot(ElementName = "String")]
public class TextString : OCRDimBase
{
[XmlAttribute(AttributeName = "WC")]
public string WC { get; set; }

Expand All @@ -33,104 +37,39 @@ public class String
}

[XmlRoot(ElementName = "TextLine")]
public class TextLine
public class TextLine : OCRDimBase
{
[XmlElement(ElementName = "String")]
public List<String> String { get; set; }

[XmlAttribute(AttributeName = "ID")]
public string Id { get; set; }

[XmlAttribute(AttributeName = "HPOS")]
public string HPos { get; set; }

[XmlAttribute(AttributeName = "VPOS")]
public string VPos { get; set; }

[XmlAttribute(AttributeName = "WIDTH")]
public string Width { get; set; }

[XmlAttribute(AttributeName = "HEIGHT")]
public string Height { get; set; }
public List<TextString> TextString { get; set; }

[XmlElement(ElementName = "SP")]
public List<SP> SP { get; set; }
}

[XmlRoot(ElementName = "TextBlock")]
public class TextBlock
public class TextBlock : OCRDimBase
{
[XmlElement(ElementName = "TextLine")]
public List<TextLine> TextLine { get; set; }

[XmlAttribute(AttributeName = "ID")]
public string Id { get; set; }

[XmlAttribute(AttributeName = "HPOS")]
public string HPos { get; set; }

[XmlAttribute(AttributeName = "VPOS")]
public string VPos { get; set; }

[XmlAttribute(AttributeName = "WIDTH")]
public string Width { get; set; }

[XmlAttribute(AttributeName = "HEIGHT")]
public string Height { get; set; }
public List<TextLine> TextLine { get; set; }
}

[XmlRoot(ElementName = "ComposedBlock")]
public class ComposedBlock
public class ComposedBlock : OCRDimBase
{
[XmlElement(ElementName = "TextBlock")]
public TextBlock TextBlock { get; set; }

[XmlAttribute(AttributeName = "ID")]
public string Id { get; set; }

[XmlAttribute(AttributeName = "HPOS")]
public string HPos { get; set; }

[XmlAttribute(AttributeName = "VPOS")]
public string VPos { get; set; }

[XmlAttribute(AttributeName = "WIDTH")]
public string Width { get; set; }

[XmlAttribute(AttributeName = "HEIGHT")]
public string Height { get; set; }
public TextBlock TextBlock { get; set; }
}

[XmlRoot(ElementName = "SP")]
public class SP
public class SP : OCRDimBase
{
[XmlAttribute(AttributeName = "WIDTH")]
public string Width { get; set; }

[XmlAttribute(AttributeName = "VPOS")]
public string VPos { get; set; }

[XmlAttribute(AttributeName = "HPOS")]
public string HPos { get; set; }
}

[XmlRoot(ElementName = "PrintSpace")]
public class PrintSpace
public class PrintSpace : OCRDimBase
{
[XmlElement(ElementName = "ComposedBlock")]
public List<ComposedBlock> ComposedBlock { get; set; }

[XmlAttribute(AttributeName = "HPOS")]
public string HPos { get; set; }

[XmlAttribute(AttributeName = "VPOS")]
public string VPos { get; set; }

[XmlAttribute(AttributeName = "WIDTH")]
public string Width { get; set; }

[XmlAttribute(AttributeName = "HEIGHT")]
public string Height { get; set; }
public List<ComposedBlock> ComposedBlock { get; set; }
}

[XmlRoot(ElementName = "Page")]
Expand Down

0 comments on commit fdb8a8f

Please sign in to comment.