Simplified the tyre detection and improved its accuracy

This commit is contained in:
2023-04-24 13:35:54 +02:00
parent 5f8f1f0704
commit 70085721f4
2 changed files with 13 additions and 41 deletions
+8 -36
View File
@@ -15,9 +15,10 @@ namespace OCR_Decode
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 HARD_TYRE_COLOR = Color.FromArgb(0xd9, 0xd8, 0xd4);
public static Color HARD_TYRE_COLOR = Color.FromArgb(0xa4, 0xa5, 0xa8);
public static Color INTER_TYRE_COLOR = Color.FromArgb(0x00, 0xa4, 0x2e);
public static Color WET_TYRE_COLOR = Color.FromArgb(0x27, 0x60, 0xa6);
public static Color EMPTY_COLOR = Color.FromArgb(0x20,0x20,0x20);
public DriverTyresWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
{
@@ -34,38 +35,9 @@ namespace OCR_Decode
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "ZONE" + ".png");
Tyre.Type type = Tyre.Type.Undefined;
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone, 2)));
int laps = -1;
//MHIWsmhiw so we can detect Soft Medium Hard Inters and Wet tyres
string text = await GetStringFromPng(tyreZone,Engine, "SMHIW", OcrImage.WindowType.Tyre);
if (text.Length == 1 && text != "")
{
//We found a tire letter
laps = 0;
text = text.ToUpper();
switch (text[0])
{
case 'S':
type = Tyre.Type.Soft;
break;
case 'M':
type = Tyre.Type.Medium;
break;
case 'H':
type = Tyre.Type.Hard;
break;
case 'I':
type = Tyre.Type.Inter;
break;
case 'W':
type = Tyre.Type.Wet;
break;
default:
type = Tyre.Type.Undefined;
break;
}
}
else
{
string number = await GetStringFromPng(tyreZone, Engine, "0123456789", OcrImage.WindowType.Tyre);
try
{
@@ -73,11 +45,8 @@ namespace OCR_Decode
}
catch
{
laps = -1;
//We could not convert the number
}
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone,2)));
}
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
return new Tyre(type, laps);
}
@@ -115,6 +84,7 @@ namespace OCR_Decode
colors.Add(HARD_TYRE_COLOR);
colors.Add(INTER_TYRE_COLOR);
colors.Add(WET_TYRE_COLOR);
colors.Add(EMPTY_COLOR);
Color closestColor = colors[0];
int closestDistance = int.MaxValue;
@@ -139,6 +109,8 @@ namespace OCR_Decode
type = Tyre.Type.Inter;
if (closestColor == WET_TYRE_COLOR)
type = Tyre.Type.Wet;
if (closestColor == EMPTY_COLOR)
return Tyre.Type.Undefined;
return type;
}
+1 -1
View File
@@ -160,7 +160,7 @@ namespace OCR_Decode
}
}
}
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
//enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
page.Dispose();
return result;
}