Cleaned Reader.cs

This commit is contained in:
2023-04-25 14:49:13 +02:00
parent a784cef87f
commit 7cb27ca69c
2 changed files with 41 additions and 11 deletions
+7 -1
View File
@@ -1,4 +1,10 @@
using System; /// Author : Maxime Rohmer
/// Date : 25/04/2023
/// File : OcrImage.cs
/// Brief : Class that contains all the post processing methods that can help with OCR
/// Version : 0.1
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
+33 -9
View File
@@ -1,4 +1,10 @@
using System; /// Author : Maxime Rohmer
/// Date : 25/04/2023
/// File : Reader.cs
/// Brief : Model that contains all the classes and methods to manage the OCR
/// Version : 0.1
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -23,7 +29,9 @@ namespace OCR_Decode
public List<string> Drivers { get => _drivers; private set => _drivers = value; } public List<string> Drivers { get => _drivers; private set => _drivers = value; }
public List<Zone> MainZones { get => _mainZones; set => _mainZones = value; } public List<Zone> MainZones { get => _mainZones; set => _mainZones = value; }
//All the image infos will be deleted in not too much time when the merge with the program that recovers the images
const string DEFAULT_IMAGE_NAME = "screen_"; const string DEFAULT_IMAGE_NAME = "screen_";
// You will defenitely have to change this if you want to be able to see debug images
public const string DEBUG_DUMP_FOLDER = @"C:\Users\Moi\Desktop\imgDump\Decode\"; public const string DEBUG_DUMP_FOLDER = @"C:\Users\Moi\Desktop\imgDump\Decode\";
const int NUMBER_OF_DRIVERS = 20; const int NUMBER_OF_DRIVERS = 20;
@@ -33,6 +41,10 @@ namespace OCR_Decode
ImagesFolder = imageFolder; ImagesFolder = imageFolder;
Load(82); Load(82);
} }
/// <summary>
/// Method that reads the JSON config file and create all the Zones and Windows
/// </summary>
/// <param name="imageNumber">The image #id on wich you want to create the zones on</param>
private void Load(int imageNumber) private void Load(int imageNumber)
{ {
MainZones = new List<Zone>(); MainZones = new List<Zone>();
@@ -159,6 +171,10 @@ namespace OCR_Decode
MessageBox.Show("Invalid JSON format: " + ex.Message); MessageBox.Show("Invalid JSON format: " + ex.Message);
} }
} }
/// <summary>
/// Changes the zones and windows to the new image
/// </summary>
/// <param name="imageNumber">The #id of the new image on wich to do OCR</param>
public void ChangeImage(int imageNumber) public void ChangeImage(int imageNumber)
{ {
Bitmap img = null; Bitmap img = null;
@@ -180,6 +196,11 @@ namespace OCR_Decode
} }
} }
} }
/// <summary>
/// Method that calls all the zones and windows to get the content they can find on the image to display them
/// </summary>
/// <param name="idImage">The id of the image we are working with</param>
/// <returns></returns>
public async Task<string> Decode(int idImage) public async Task<string> Decode(int idImage)
{ {
string result = ""; string result = "";
@@ -198,9 +219,8 @@ namespace OCR_Decode
mainResults.Add(await z.Decode(Drivers)); mainResults.Add(await z.Decode(Drivers));
} }
break; break;
//Next there will be the title and laps added //Next there could be a Title Zone and TrackInfoZone
} }
} }
//Display //Display
@@ -212,6 +232,11 @@ namespace OCR_Decode
return result; return result;
} }
/// <summary>
/// Method that can be used to convert an amount of miliseconds into a more readable human form
/// </summary>
/// <param name="amountOfMs">The given amount of miliseconds ton convert</param>
/// <returns></returns>
public static string ConvertMsToTime(int amountOfMs) public static string ConvertMsToTime(int amountOfMs)
{ {
//Convert.ToInt32 would round upand I dont want that //Convert.ToInt32 would round upand I dont want that
@@ -221,6 +246,11 @@ namespace OCR_Decode
return minuts + ":" + seconds.ToString("00") + ":" + ms.ToString("000"); return minuts + ":" + seconds.ToString("00") + ":" + ms.ToString("000");
} }
/// <summary>
/// Old method that can draw on an image where the windows and zones are created. mostly used for debugging
/// </summary>
/// <param name="idImage">the #id of the image we are working with</param>
/// <returns></returns>
public Bitmap Draw(int idImage) public Bitmap Draw(int idImage)
{ {
Bitmap result; Bitmap result;
@@ -241,12 +271,6 @@ namespace OCR_Decode
int count = 0; int count = 0;
foreach (Zone zz in z.Zones) foreach (Zone zz in z.Zones)
{ {
//string driverFolder = DEBUG_DUMP_FOLDER + "driver" + count + "\\";
//if (!Directory.Exists(driverFolder))
//Directory.CreateDirectory(driverFolder);
//zz.ZoneImage.Save(driverFolder + "FullImage.png");
g.DrawRectangle(Pens.Red, z.Bounds); g.DrawRectangle(Pens.Red, z.Bounds);
foreach (Window w in zz.Windows) foreach (Window w in zz.Windows)
{ {