Simplified the tyre detection and improved its accuracy
This commit is contained in:
@@ -15,9 +15,10 @@ namespace OCR_Decode
|
|||||||
|
|
||||||
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(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 INTER_TYRE_COLOR = Color.FromArgb(0x00, 0xa4, 0x2e);
|
||||||
public static Color WET_TYRE_COLOR = Color.FromArgb(0x27, 0x60, 0xa6);
|
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)
|
public DriverTyresWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
|
||||||
{
|
{
|
||||||
@@ -34,50 +35,18 @@ namespace OCR_Decode
|
|||||||
|
|
||||||
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "ZONE" + ".png");
|
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "ZONE" + ".png");
|
||||||
Tyre.Type type = Tyre.Type.Undefined;
|
Tyre.Type type = Tyre.Type.Undefined;
|
||||||
|
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone, 2)));
|
||||||
int laps = -1;
|
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);
|
string number = await GetStringFromPng(tyreZone, Engine, "0123456789", OcrImage.WindowType.Tyre);
|
||||||
if (text.Length == 1 && text != "")
|
try
|
||||||
{
|
{
|
||||||
//We found a tire letter
|
laps = Convert.ToInt32(number);
|
||||||
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
|
catch
|
||||||
{
|
{
|
||||||
string number = await GetStringFromPng(tyreZone, Engine, "0123456789", OcrImage.WindowType.Tyre);
|
//We could not convert the number
|
||||||
try
|
|
||||||
{
|
|
||||||
laps = Convert.ToInt32(number);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
laps = -1;
|
|
||||||
}
|
|
||||||
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone,2)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//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);
|
||||||
}
|
}
|
||||||
@@ -115,6 +84,7 @@ namespace OCR_Decode
|
|||||||
colors.Add(HARD_TYRE_COLOR);
|
colors.Add(HARD_TYRE_COLOR);
|
||||||
colors.Add(INTER_TYRE_COLOR);
|
colors.Add(INTER_TYRE_COLOR);
|
||||||
colors.Add(WET_TYRE_COLOR);
|
colors.Add(WET_TYRE_COLOR);
|
||||||
|
colors.Add(EMPTY_COLOR);
|
||||||
|
|
||||||
Color closestColor = colors[0];
|
Color closestColor = colors[0];
|
||||||
int closestDistance = int.MaxValue;
|
int closestDistance = int.MaxValue;
|
||||||
@@ -139,6 +109,8 @@ namespace OCR_Decode
|
|||||||
type = Tyre.Type.Inter;
|
type = Tyre.Type.Inter;
|
||||||
if (closestColor == WET_TYRE_COLOR)
|
if (closestColor == WET_TYRE_COLOR)
|
||||||
type = Tyre.Type.Wet;
|
type = Tyre.Type.Wet;
|
||||||
|
if (closestColor == EMPTY_COLOR)
|
||||||
|
return Tyre.Type.Undefined;
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
page.Dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user