Cleaned some more files
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
using System;
|
/// Author : Maxime Rohmer
|
||||||
|
/// Date : 25/04/2023
|
||||||
|
/// File : DriverSector1Window.cs
|
||||||
|
/// Brief : Window that contains infos about the first sector of a driver
|
||||||
|
/// Version : 0.1
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -14,6 +20,10 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Sector 1";
|
Name = "Sector 1";
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes the sector
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>the sector time in int (ms)</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector, Engine);
|
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector, Engine);
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
using System;
|
/// Author : Maxime Rohmer
|
||||||
|
/// Date : 25/04/2023
|
||||||
|
/// File : DriverSector2Window.cs
|
||||||
|
/// Brief : Window that contains infos about the second sector of a driver
|
||||||
|
/// Version : 0.1
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -14,6 +21,10 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Sector 2";
|
Name = "Sector 2";
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes the sector
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>the sector time in int (ms)</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector,Engine);
|
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector,Engine);
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
using System;
|
/// Author : Maxime Rohmer
|
||||||
|
/// Date : 25/04/2023
|
||||||
|
/// File : DriverSector3Window.cs
|
||||||
|
/// Brief : Window that contains infos about the third sector of a driver
|
||||||
|
/// Version : 0.1
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@@ -15,6 +21,10 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Sector 3";
|
Name = "Sector 3";
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes the sector
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>the sector time in int (ms)</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector,Engine);
|
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector,Engine);
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
using System;
|
/// Author : Maxime Rohmer
|
||||||
|
/// Date : 25/04/2023
|
||||||
|
/// File : DriverTyresWindow.cs
|
||||||
|
/// Brief : Window that contains infos about tyres and that can decode them
|
||||||
|
/// Version : 0.1
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@@ -14,6 +20,7 @@ namespace OCR_Decode
|
|||||||
private static Random rnd = new Random();
|
private static Random rnd = new Random();
|
||||||
int seed = rnd.Next(0,10000);
|
int seed = rnd.Next(0,10000);
|
||||||
|
|
||||||
|
//Those are the colors I found but you can change them if they change in the future like in 2019
|
||||||
public static Color SOFT_TYRE_COLOR = Color.FromArgb(0xff, 0x00, 0x00);
|
public static Color SOFT_TYRE_COLOR = Color.FromArgb(0xff, 0x00, 0x00);
|
||||||
public static Color MEDIUM_TYRE_COLOR = Color.FromArgb(0xf5, 0xbf, 0x00);
|
public static Color MEDIUM_TYRE_COLOR = Color.FromArgb(0xf5, 0xbf, 0x00);
|
||||||
public static Color HARD_TYRE_COLOR = Color.FromArgb(0xa4, 0xa5, 0xa8);
|
public static Color HARD_TYRE_COLOR = Color.FromArgb(0xa4, 0xa5, 0xa8);
|
||||||
@@ -25,15 +32,21 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Tyres";
|
Name = "Tyres";
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// This will decode the content of the image
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>And object containing what was on the image</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
//WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "testTyres" + rnd.Next(0, 1000) + ".png");
|
|
||||||
return await GetTyreInfos();
|
return await GetTyreInfos();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Method that will decode whats on the image and return the tyre infos it could manage to recover
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A tyre object containing tyre infos</returns>
|
||||||
private async Task<Tyre> GetTyreInfos()
|
private async Task<Tyre> GetTyreInfos()
|
||||||
{
|
{
|
||||||
Bitmap tyreZone = GetSmallBitmapFromBigOne(WindowImage, FindTyreZone());
|
Bitmap tyreZone = GetSmallBitmapFromBigOne(WindowImage, FindTyreZone());
|
||||||
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "NewTyreZone_"+seed+".png");
|
|
||||||
Tyre.Type type = Tyre.Type.Undefined;
|
Tyre.Type type = Tyre.Type.Undefined;
|
||||||
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(tyreZone));
|
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(tyreZone));
|
||||||
int laps = -1;
|
int laps = -1;
|
||||||
@@ -51,12 +64,13 @@ namespace OCR_Decode
|
|||||||
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
||||||
return new Tyre(type, laps);
|
return new Tyre(type, laps);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Finds where the important part of the image is
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A rectangle containing position and dimensions of the important part of the image</returns>
|
||||||
private Rectangle FindTyreZone()
|
private Rectangle FindTyreZone()
|
||||||
{
|
{
|
||||||
Bitmap bmp = WindowImage;
|
Bitmap bmp = WindowImage;
|
||||||
|
|
||||||
//bmp.Save(Reader.DEBUG_DUMP_FOLDER + "OldTyreZone_" + seed + ".png");
|
|
||||||
|
|
||||||
int currentPosition = bmp.Width;
|
int currentPosition = bmp.Width;
|
||||||
int height = bmp.Height / 2;
|
int height = bmp.Height / 2;
|
||||||
Color limitColor = Color.FromArgb(0x50, 0x50, 0x50);
|
Color limitColor = Color.FromArgb(0x50, 0x50, 0x50);
|
||||||
@@ -79,10 +93,17 @@ namespace OCR_Decode
|
|||||||
return new Rectangle(CorrectedX, CorrectedY, newWindowSize.Width, newWindowSize.Height);
|
return new Rectangle(CorrectedX, CorrectedY, newWindowSize.Width, newWindowSize.Height);
|
||||||
}
|
}
|
||||||
//This method has been created with the help of chatGPT
|
//This method has been created with the help of chatGPT
|
||||||
|
/// <summary>
|
||||||
|
/// Methods that compares a list of colors to see wich is the closest from the input color and decide wich tyre type it is
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputColor">The color that you found</param>
|
||||||
|
/// <returns>The tyre type</returns>
|
||||||
public Tyre.Type GetTyreTypeFromColor(Color inputColor)
|
public Tyre.Type GetTyreTypeFromColor(Color inputColor)
|
||||||
{
|
{
|
||||||
Tyre.Type type = Tyre.Type.Undefined;
|
Tyre.Type type = Tyre.Type.Undefined;
|
||||||
List<Color> colors = new List<Color>();
|
List<Color> colors = new List<Color>();
|
||||||
|
//dont forget that if for some reason someday F1 adds a new Tyre type you will need to add it in the constants but also here in the list
|
||||||
|
//You will also need to add it below in the Tyre object's enum and add an if in the end of this method
|
||||||
colors.Add(SOFT_TYRE_COLOR);
|
colors.Add(SOFT_TYRE_COLOR);
|
||||||
colors.Add(MEDIUM_TYRE_COLOR);
|
colors.Add(MEDIUM_TYRE_COLOR);
|
||||||
colors.Add(HARD_TYRE_COLOR);
|
colors.Add(HARD_TYRE_COLOR);
|
||||||
@@ -102,11 +123,6 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Bitmap colorBmp = new Bitmap(200, 100);
|
|
||||||
//Graphics g = Graphics.FromImage(colorBmp);
|
|
||||||
//g.FillRectangle(new SolidBrush(closestColor), new Rectangle(0, 0, colorBmp.Width, colorBmp.Height));
|
|
||||||
//colorBmp.Save(Reader.DEBUG_DUMP_FOLDER+"AVGCOLOR_"+closestColor.ToString()+"_"+seed+".png");
|
|
||||||
|
|
||||||
//We cant use a switch as the colors cant be constants ...
|
//We cant use a switch as the colors cant be constants ...
|
||||||
if (closestColor == SOFT_TYRE_COLOR)
|
if (closestColor == SOFT_TYRE_COLOR)
|
||||||
type = Tyre.Type.Soft;
|
type = Tyre.Type.Soft;
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ namespace OCR_Decode
|
|||||||
Windows.Add(window);
|
Windows.Add(window);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calls all the zones and windows to do OCR and to give back the results so we can send them to the model
|
/// Calls all the windows to do OCR and to give back the results so we can send them to the model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="driverList">A list of all the driver in the race to help with text recognition</param>
|
/// <param name="driverList">A list of all the driver in the race to help with text recognition</param>
|
||||||
/// <returns>A driver data object that contains all the infos about a driver</returns>
|
/// <returns>A driver data object that contains all the infos about a driver</returns>
|
||||||
|
|||||||
Reference in New Issue
Block a user