Optimised and verified the position detection using OCR
This commit is contained in:
+11
-5
@@ -41,22 +41,28 @@ namespace Test_Merge
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">The type of the window. Depending on it different enhancing features will be applied</param>
|
/// <param name="type">The type of the window. Depending on it different enhancing features will be applied</param>
|
||||||
/// <returns>The enhanced Bitmap</returns>
|
/// <returns>The enhanced Bitmap</returns>
|
||||||
public Bitmap Enhance(WindowType type = WindowType.Text)
|
public Bitmap Enhance(int id,WindowType type = WindowType.Text)
|
||||||
{
|
{
|
||||||
Bitmap outputBitmap = (Bitmap)InputBitmap.Clone();
|
Bitmap outputBitmap = (Bitmap)InputBitmap.Clone();
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case WindowType.LapTime:
|
case WindowType.LapTime:
|
||||||
|
outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\raw_" + id + ".png");
|
||||||
|
|
||||||
outputBitmap = Tresholding(outputBitmap, 185);
|
outputBitmap = Tresholding(outputBitmap, 185);
|
||||||
//outputBitmap = Resize(outputBitmap, 2);
|
outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\treshold_" + id + ".png");
|
||||||
|
|
||||||
outputBitmap = Dilatation(outputBitmap, 1);
|
outputBitmap = Dilatation(outputBitmap, 1);
|
||||||
|
outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\dilatation_" + id + ".png");
|
||||||
|
|
||||||
outputBitmap = Erode(outputBitmap, 1);
|
outputBitmap = Erode(outputBitmap, 1);
|
||||||
|
outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\Final_erode_" + id + ".png");
|
||||||
break;
|
break;
|
||||||
case WindowType.Text:
|
case WindowType.Text:
|
||||||
outputBitmap = InvertColors(outputBitmap);
|
outputBitmap.Save(Window.STRING_DEBUG_FOLDER + @"\raw_" + id + ".png");
|
||||||
|
|
||||||
outputBitmap = Tresholding(outputBitmap, 165);
|
outputBitmap = Tresholding(outputBitmap, 165);
|
||||||
//outputBitmap = Resize(outputBitmap, 2);
|
outputBitmap.Save(Window.STRING_DEBUG_FOLDER + @"\Final_treshold_" + id + ".png");
|
||||||
outputBitmap = Dilatation(outputBitmap, 1);
|
|
||||||
break;
|
break;
|
||||||
case WindowType.Tyre:
|
case WindowType.Tyre:
|
||||||
outputBitmap = RemoveUseless(outputBitmap);
|
outputBitmap = RemoveUseless(outputBitmap);
|
||||||
|
|||||||
+40
-3
@@ -19,6 +19,16 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
public class Window
|
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 Rectangle _bounds;
|
||||||
private Bitmap _image;
|
private Bitmap _image;
|
||||||
private string _name;
|
private string _name;
|
||||||
@@ -28,6 +38,8 @@ namespace Test_Merge
|
|||||||
public string Name { get => _name; protected set => _name = value; }
|
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
|
//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");
|
public static DirectoryInfo TESS_DATA_FOLDER = new DirectoryInfo(@"C:\Users\Moi\Pictures\SeleniumScreens\TessData");
|
||||||
|
//Debug
|
||||||
|
public static Random rnd = new Random();
|
||||||
|
|
||||||
public Bitmap WindowImage
|
public Bitmap WindowImage
|
||||||
{
|
{
|
||||||
@@ -49,6 +61,24 @@ namespace Test_Merge
|
|||||||
Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||||
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
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>
|
/// <summary>
|
||||||
/// Method that will have to be used by the childrens to let the model make them decode the images they have
|
/// 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 = "";
|
string rawResult = "";
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
//Debug
|
||||||
|
int salt = rnd.Next(0,999999);
|
||||||
|
|
||||||
switch (windowType)
|
switch (windowType)
|
||||||
{
|
{
|
||||||
case OcrImage.WindowType.Sector:
|
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));
|
var tessImage = Pix.LoadFromMemory(ImageToByte(enhancedImage));
|
||||||
|
|
||||||
@@ -195,7 +228,8 @@ namespace Test_Merge
|
|||||||
//For no apparent reason im going to delete the first
|
//For no apparent reason im going to delete the first
|
||||||
seconds = Convert.ToInt32(rawNumbers[0][1].ToString() + rawNumbers[0][2].ToString());
|
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());
|
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());
|
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 = "";
|
string result = "";
|
||||||
|
|
||||||
|
//Debug
|
||||||
|
int salt = rnd.Next(0, 999999);
|
||||||
|
|
||||||
Engine.SetVariable("tessedit_char_whitelist", allowedChars);
|
Engine.SetVariable("tessedit_char_whitelist", allowedChars);
|
||||||
|
|
||||||
Bitmap rawData = image;
|
Bitmap rawData = image;
|
||||||
Bitmap enhancedImage = new OcrImage(rawData).Enhance(windowType);
|
Bitmap enhancedImage = new OcrImage(rawData).Enhance(salt,windowType);
|
||||||
|
|
||||||
Page page = Engine.Process(enhancedImage);
|
Page page = Engine.Process(enhancedImage);
|
||||||
using (var iter = page.GetIterator())
|
using (var iter = page.GetIterator())
|
||||||
|
|||||||
+2
-2
@@ -106,8 +106,8 @@ namespace Test_Merge
|
|||||||
//result.LapTime = (int)await (w as DriverLapTimeWindow).DecodePng();
|
//result.LapTime = (int)await (w as DriverLapTimeWindow).DecodePng();
|
||||||
result.LapTime = 0;
|
result.LapTime = 0;
|
||||||
if (w is DriverPositionWindow)
|
if (w is DriverPositionWindow)
|
||||||
//result.Position = (int)await (w as DriverPositionWindow).DecodePng();
|
result.Position = (int)await (w as DriverPositionWindow).DecodePng();
|
||||||
result.Position = 0;
|
//result.Position = 0;
|
||||||
if (w is DriverSectorWindow)
|
if (w is DriverSectorWindow)
|
||||||
{
|
{
|
||||||
sectorCount++;
|
sectorCount++;
|
||||||
|
|||||||
Reference in New Issue
Block a user