Optimised and verified the position detection using OCR

This commit is contained in:
2023-05-12 08:57:58 +02:00
parent 592025e283
commit 863ce1922f
4 changed files with 55 additions and 12 deletions
+41 -4
View File
@@ -19,6 +19,16 @@ namespace Test_Merge
{
public class Window
{
public const string STRING_DEBUG_FOLDER = "./GetString";
public const string LAPTIME_DEBUG_FOLDER = "./LapTime";
public const string GAPTOLEADER_DEBUG_FOLDER = "./Gap";
public const string SECTOR1_DEBUG_FOLDER = "./Sector1";
public const string SECTOR2_DEBUG_FOLDER = "./Sector2";
public const string SECTOR3_DEBUG_FOLDER = "./Sector3";
public const string DRS_DEBUG_FOLDER = "./DRS";
public const string TYRE_DEBUG_FOLDER = "./Tyre";
private Rectangle _bounds;
private Bitmap _image;
private string _name;
@@ -28,6 +38,8 @@ namespace Test_Merge
public string Name { get => _name; protected set => _name = value; }
//This will have to be changed if you want to make it run on your machine
public static DirectoryInfo TESS_DATA_FOLDER = new DirectoryInfo(@"C:\Users\Moi\Pictures\SeleniumScreens\TessData");
//Debug
public static Random rnd = new Random();
public Bitmap WindowImage
{
@@ -49,6 +61,24 @@ namespace Test_Merge
Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
}
//DEBUG
if (!Directory.Exists(STRING_DEBUG_FOLDER))
Directory.CreateDirectory(STRING_DEBUG_FOLDER);
if (!Directory.Exists(LAPTIME_DEBUG_FOLDER))
Directory.CreateDirectory(LAPTIME_DEBUG_FOLDER);
if (!Directory.Exists(GAPTOLEADER_DEBUG_FOLDER))
Directory.CreateDirectory(GAPTOLEADER_DEBUG_FOLDER);
if (!Directory.Exists(SECTOR1_DEBUG_FOLDER))
Directory.CreateDirectory(SECTOR1_DEBUG_FOLDER);
if (!Directory.Exists(SECTOR2_DEBUG_FOLDER))
Directory.CreateDirectory(SECTOR2_DEBUG_FOLDER);
if (!Directory.Exists(SECTOR3_DEBUG_FOLDER))
Directory.CreateDirectory(SECTOR3_DEBUG_FOLDER);
if (!Directory.Exists(DRS_DEBUG_FOLDER))
Directory.CreateDirectory(DRS_DEBUG_FOLDER);
if (!Directory.Exists(TYRE_DEBUG_FOLDER))
Directory.CreateDirectory(TYRE_DEBUG_FOLDER);
}
/// <summary>
/// Method that will have to be used by the childrens to let the model make them decode the images they have
@@ -93,6 +123,9 @@ namespace Test_Merge
string rawResult = "";
int result = 0;
//Debug
int salt = rnd.Next(0,999999);
switch (windowType)
{
case OcrImage.WindowType.Sector:
@@ -113,7 +146,7 @@ namespace Test_Merge
}
Bitmap enhancedImage = new OcrImage(image).Enhance(windowType);
Bitmap enhancedImage = new OcrImage(image).Enhance(salt,windowType);
var tessImage = Pix.LoadFromMemory(ImageToByte(enhancedImage));
@@ -184,7 +217,7 @@ namespace Test_Merge
{
//A lap time is fucked
Console.Write("Fuck");
}
}
}
if (windowType == OcrImage.WindowType.Sector)
{
@@ -195,7 +228,8 @@ namespace Test_Merge
//For no apparent reason im going to delete the first
seconds = Convert.ToInt32(rawNumbers[0][1].ToString() + rawNumbers[0][2].ToString());
}
if (rawNumbers[0].Length == 2) {
if (rawNumbers[0].Length == 2)
{
seconds = Convert.ToInt32(rawNumbers[0][0].ToString() + rawNumbers[0][1].ToString());
}
int ms = Convert.ToInt32(rawNumbers[1][0].ToString() + rawNumbers[1][1].ToString() + rawNumbers[1][2].ToString());
@@ -295,10 +329,13 @@ namespace Test_Merge
{
string result = "";
//Debug
int salt = rnd.Next(0, 999999);
Engine.SetVariable("tessedit_char_whitelist", allowedChars);
Bitmap rawData = image;
Bitmap enhancedImage = new OcrImage(rawData).Enhance(windowType);
Bitmap enhancedImage = new OcrImage(rawData).Enhance(salt,windowType);
Page page = Engine.Process(enhancedImage);
using (var iter = page.GetIterator())