Finally all work (Except for tyres and DRS)

This commit is contained in:
2023-04-06 08:53:31 +02:00
parent 9af92f06b0
commit 308ef06a6d
8 changed files with 65 additions and 20 deletions
+24 -6
View File
@@ -57,14 +57,29 @@ namespace OCR_Decode
return stream.ToArray();
}
}
public static int GetTimeFromPng(Bitmap wImage)
public static int GetTimeFromPng(Bitmap wImage,OcrImage.WindowType type)
{
string rawResult = "";
int result = 0;
Engine.SetVariable("tessedit_char_whitelist", "0123456789:.");
switch (type)
{
case OcrImage.WindowType.Sector:
Engine.SetVariable("tessedit_char_whitelist", "0123456789.");
break;
case OcrImage.WindowType.LapTime:
Engine.SetVariable("tessedit_char_whitelist", "0123456789.:");
break;
case OcrImage.WindowType.Gap:
Engine.SetVariable("tessedit_char_whitelist", "0123456789.+");
break;
default:
Engine.SetVariable("tessedit_char_whitelist", "");
break;
}
Bitmap enhancedImage = new OcrImage(wImage).Enhance();
Bitmap enhancedImage = new OcrImage(wImage).Enhance(type);
var tessImage = Pix.LoadFromMemory(ImageToByte(enhancedImage));
@@ -93,9 +108,9 @@ namespace OCR_Decode
List<string> rawNumbers;
//Removes all non digit chars except for the important ones
//We will need to change this when trying to see the Leader and Lap texts
//string cleanedResult = Regex.Replace(rawResult, "[^0-9.:]", "");
//In the gaps we can find '+' but we dont care about it its redondant
if(type == OcrImage.WindowType.Gap)
rawResult = Regex.Replace(rawResult, "[^0-9.:]", "");
//Splits into minuts seconds miliseconds
rawNumbers = rawResult.Split('.', ':').ToList<string>();
@@ -164,6 +179,9 @@ namespace OCR_Decode
result += iter.GetText(PageIteratorLevel.Word);
} while (iter.Next(PageIteratorLevel.Word));
}
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(result, "[^0-9A-Za-z]", "") + ".png");
page.Dispose();
return result;
}