Lap times are better at differenciating '4' from '1' and the tyres are less suceptible to be saved in DB with outragious numbers of laps

This commit is contained in:
2023-05-18 11:57:32 +02:00
parent b7676b90c2
commit 417cb7d8eb
3 changed files with 70 additions and 13 deletions

View File

@@ -60,6 +60,11 @@ namespace Test_Merge
laps = 0;
}
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
//71 is the most laps an f1 race is ever going to have (mexico)
if (laps > 75)
laps = 0;
return new Tyre(type, laps);
}
/// <summary>
@@ -73,8 +78,8 @@ namespace Test_Merge
int height = bmp.Height / 2;
Color limitColor = Color.FromArgb(0x50, 0x50, 0x50);
Color currentColor = Color.FromArgb(0, 0, 0);
Size newWindowSize = new Size(bmp.Height - Convert.ToInt32((float)bmp.Height / 100f * 25f), bmp.Height - Convert.ToInt32((float)bmp.Height / 100f * 35f));
//25F
Size newWindowSize = new Size(bmp.Height - Convert.ToInt32((float)bmp.Height / 100f * 25f), bmp.Height - Convert.ToInt32((float)bmp.Height / 100f * 35f));
while (currentColor.R <= limitColor.R && currentColor.G <= limitColor.G && currentColor.B <= limitColor.B && currentPosition > 0)
{

View File

@@ -64,20 +64,17 @@ namespace Test_Merge
outputBitmap = VanishOxyAction(outputBitmap);
//outputBitmap.Save(Window.SECTOR1_DEBUG_FOLDER + @"\vanish_" + id + ".png");
outputBitmap = Tresholding(outputBitmap,150);
outputBitmap = Tresholding(outputBitmap, 150);
//outputBitmap.Save(Window.SECTOR1_DEBUG_FOLDER + @"\Final_treshold_" + id + ".png");
break;
case WindowType.LapTime:
//outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\raw_" + id + ".png");
outputBitmap = Tresholding(outputBitmap, 165);
//outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\treshold_" + id + ".png");
outputBitmap = Tresholding(outputBitmap,185);
//outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\Treshold_" + id + ".png");
outputBitmap = Dilatation(outputBitmap, 1);
//outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\dilatation_" + id + ".png");
outputBitmap = Erode(outputBitmap, 1);
//outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\Final_erode_" + id + ".png");
outputBitmap = SobelEdgeDetection(outputBitmap);
//outputBitmap.Save(Window.LAPTIME_DEBUG_FOLDER + @"\SobelDetection_" + id + ".png");
break;
case WindowType.Text:
//outputBitmap.Save(Window.STRING_DEBUG_FOLDER + @"\raw_" + id + ".png");
@@ -86,7 +83,7 @@ namespace Test_Merge
//outputBitmap.Save(Window.STRING_DEBUG_FOLDER + @"\Final_treshold_" + id + ".png");
break;
case WindowType.Tyre:
//outputBitmap.Save(Window.TYRE_DEBUG_FOLDER + @"\raw_" + id + ".png");
outputBitmap.Save(Window.TYRE_DEBUG_FOLDER + @"\raw_" + id + ".png");
outputBitmap = RemoveUseless(outputBitmap);
//outputBitmap.Save(Window.TYRE_DEBUG_FOLDER + @"\uselessRemoved_" + id + ".png");
@@ -130,7 +127,15 @@ namespace Test_Merge
//Those a specific values to correct the weights so its more pleasing to the human eye
int gray = (int)(red * 0.3 + green * 0.59 + blue * 0.11);
pixel[0] = pixel[1] = pixel[2] = (byte)gray;
//This is not a proper treshold method but it is helping the sobel edge detection
if(gray <= F1TV_BACKGROUND_TRESHOLD.R)
{
pixel[0] = pixel[1] = pixel[2] = 0;
}
else
{
pixel[0] = pixel[1] = pixel[2] = (byte)gray;
}
}
}
}
@@ -138,6 +143,49 @@ namespace Test_Merge
return inputBitmap;
}
private Bitmap SobelEdgeDetection(Bitmap grayscaleImage)
{
// Create a new bitmap for the edges
Bitmap edgesImage = new Bitmap(grayscaleImage.Width, grayscaleImage.Height);
// Define the Sobel operators
int[,] sobelX = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } };
int[,] sobelY = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } };
// Apply the Sobel operators and normalize the gradients
for (int y = 1; y < grayscaleImage.Height - 1; y++)
{
for (int x = 1; x < grayscaleImage.Width - 1; x++)
{
int gradientX = CalculateGradient(grayscaleImage, sobelX, x, y);
int gradientY = CalculateGradient(grayscaleImage, sobelY, x, y);
int gradient = (int)Math.Sqrt(gradientX * gradientX + gradientY * gradientY);
// Normalize the gradient value
gradient = Math.Min(255, Math.Max(0, gradient));
edgesImage.SetPixel(x, y, Color.FromArgb(gradient, gradient, gradient));
}
}
return edgesImage;
}
private int CalculateGradient(Bitmap grayscaleImage, int[,] sobelOperator, int x, int y)
{
int gradient = 0;
for (int j = -1; j <= 1; j++)
{
for (int i = -1; i <= 1; i++)
{
int pixelX = grayscaleImage.GetPixel(x + i, y + j).R;
gradient += sobelOperator[j + 1, i + 1] * pixelX;
}
}
return gradient;
}
public static Bitmap VanishOxyAction(Bitmap inputBitmap)
{
Rectangle rect = new Rectangle(0, 0, inputBitmap.Width, inputBitmap.Height);
@@ -331,7 +379,7 @@ namespace Test_Merge
int G = pixel[1];
int R = pixel[2];
if (R >= F1TV_BACKGROUND_TRESHOLD.R + 15 || G >= F1TV_BACKGROUND_TRESHOLD.G + 15 || B >= F1TV_BACKGROUND_TRESHOLD.B + 15)
if (R >= F1TV_BACKGROUND_TRESHOLD.R +25|| G >= F1TV_BACKGROUND_TRESHOLD.G +25|| B >= F1TV_BACKGROUND_TRESHOLD.B +25)
{
pixel[0] = 0xFF;
pixel[1] = 0xFF;

View File

@@ -242,6 +242,10 @@ namespace Test_Merge
mainResults.Add(data);
DriverDataLogs[i].Add(data);
//Tries to fix the tyres
if (data.CurrentTyre.NumberOfLaps > DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 3)
data.CurrentTyre.NumberOfLaps = DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 1;
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
{
//Checking if its a new lap