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
+8 -2
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.Linq;
using System.Text;
@@ -16,7 +22,7 @@ namespace OCR_Decode
{
//this is a hardcoded value based on the colors of the F1TV data channel background you can change it if sometime in the future the color changes
//Any color that has any of its R,G or B channel higher than the treshold will be considered as being usefull information
public static Color F1TV_BACKGROUND_TRESHOLD = Color.FromArgb(0x50,0x50,0x50);
public static Color F1TV_BACKGROUND_TRESHOLD = Color.FromArgb(0x50, 0x50, 0x50);
Bitmap InputBitmap;
public enum WindowType
{
+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.Linq;
using System.Text;
@@ -23,7 +29,9 @@ namespace OCR_Decode
public List<string> Drivers { get => _drivers; private set => _drivers = 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_";
// 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\";
const int NUMBER_OF_DRIVERS = 20;
@@ -33,6 +41,10 @@ namespace OCR_Decode
ImagesFolder = imageFolder;
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)
{
MainZones = new List<Zone>();
@@ -159,6 +171,10 @@ namespace OCR_Decode
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)
{
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)
{
string result = "";
@@ -198,9 +219,8 @@ namespace OCR_Decode
mainResults.Add(await z.Decode(Drivers));
}
break;
//Next there will be the title and laps added
//Next there could be a Title Zone and TrackInfoZone
}
}
//Display
@@ -212,6 +232,11 @@ namespace OCR_Decode
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)
{
//Convert.ToInt32 would round upand I dont want that
@@ -221,6 +246,11 @@ namespace OCR_Decode
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)
{
Bitmap result;
@@ -241,12 +271,6 @@ namespace OCR_Decode
int count = 0;
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);
foreach (Window w in zz.Windows)
{