Finally all work (Except for tyres and DRS)
This commit is contained in:
@@ -15,7 +15,7 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override object DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int result = GetTimeFromPng(WindowImage);
|
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.Gap);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override object DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int result = GetTimeFromPng(WindowImage);
|
int result = GetTimeFromPng(WindowImage,OcrImage.WindowType.LapTime);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override object DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int result = GetTimeFromPng(WindowImage);
|
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override object DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int result = GetTimeFromPng(WindowImage);
|
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override object DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int result = GetTimeFromPng(WindowImage);
|
int result = GetTimeFromPng(WindowImage,OcrImage.WindowType.Sector);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-8
@@ -11,22 +11,49 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
//AT LEAST PART OF THIS CLASS HAVE BEEN CREATED USING CHATGPT
|
//AT LEAST PART OF THIS CLASS HAVE BEEN CREATED USING CHATGPT
|
||||||
//Just so you know
|
//Just so you know
|
||||||
internal class OcrImage
|
public class OcrImage
|
||||||
{
|
{
|
||||||
Bitmap InputImage;
|
Bitmap InputImage;
|
||||||
|
public enum WindowType
|
||||||
|
{
|
||||||
|
LapTime,
|
||||||
|
Text,
|
||||||
|
Sector,
|
||||||
|
Gap,
|
||||||
|
}
|
||||||
public OcrImage(Bitmap inputImage)
|
public OcrImage(Bitmap inputImage)
|
||||||
{
|
{
|
||||||
InputImage = inputImage;
|
InputImage = inputImage;
|
||||||
}
|
}
|
||||||
public Bitmap Enhance()
|
public Bitmap Enhance(WindowType type = WindowType.Text)
|
||||||
{
|
{
|
||||||
Bitmap result = (Bitmap)InputImage.Clone();
|
Bitmap result = (Bitmap)InputImage.Clone();
|
||||||
result = Grayscale(result);
|
|
||||||
result = InvertColors(result);
|
switch (type)
|
||||||
//result = Resize(result);
|
{
|
||||||
result = Tresholding(result, 165);
|
case WindowType.LapTime:
|
||||||
result = Resize(result);
|
result = Grayscale(result);
|
||||||
result = Resize(result);
|
result = InvertColors(result);
|
||||||
|
result = Tresholding(result, 165);
|
||||||
|
result = Resize(result);
|
||||||
|
result = Resize(result);
|
||||||
|
break;
|
||||||
|
case WindowType.Text:
|
||||||
|
result = Grayscale(result);
|
||||||
|
result = InvertColors(result);
|
||||||
|
result = Tresholding(result, 165);
|
||||||
|
//result = Erode(result,1);
|
||||||
|
result = Resize(result);
|
||||||
|
result = Dilatation(result, 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = Tresholding(result, 165);
|
||||||
|
result = Resize(result);
|
||||||
|
result = Resize(result);
|
||||||
|
result = Erode(result, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//result = Dilatation(result, 1);
|
//result = Dilatation(result, 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ namespace OCR_Decode
|
|||||||
int seconds = (int)((amountOfMs - (minuts*60f*1000f))/1000);
|
int seconds = (int)((amountOfMs - (minuts*60f*1000f))/1000);
|
||||||
int ms = amountOfMs - ((minuts * 60 * 1000) + (seconds * 1000));
|
int ms = amountOfMs - ((minuts * 60 * 1000) + (seconds * 1000));
|
||||||
|
|
||||||
return minuts + ":" + seconds + ":" + ms;
|
return minuts + ":" + seconds.ToString("00") + ":" + ms.ToString("000");
|
||||||
}
|
}
|
||||||
public Bitmap Draw(int idImage)
|
public Bitmap Draw(int idImage)
|
||||||
{
|
{
|
||||||
|
|||||||
+24
-6
@@ -57,14 +57,29 @@ namespace OCR_Decode
|
|||||||
return stream.ToArray();
|
return stream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static int GetTimeFromPng(Bitmap wImage)
|
public static int GetTimeFromPng(Bitmap wImage,OcrImage.WindowType type)
|
||||||
{
|
{
|
||||||
string rawResult = "";
|
string rawResult = "";
|
||||||
int result = 0;
|
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));
|
var tessImage = Pix.LoadFromMemory(ImageToByte(enhancedImage));
|
||||||
|
|
||||||
@@ -93,9 +108,9 @@ namespace OCR_Decode
|
|||||||
|
|
||||||
List<string> rawNumbers;
|
List<string> rawNumbers;
|
||||||
|
|
||||||
//Removes all non digit chars except for the important ones
|
//In the gaps we can find '+' but we dont care about it its redondant
|
||||||
//We will need to change this when trying to see the Leader and Lap texts
|
if(type == OcrImage.WindowType.Gap)
|
||||||
//string cleanedResult = Regex.Replace(rawResult, "[^0-9.:]", "");
|
rawResult = Regex.Replace(rawResult, "[^0-9.:]", "");
|
||||||
|
|
||||||
//Splits into minuts seconds miliseconds
|
//Splits into minuts seconds miliseconds
|
||||||
rawNumbers = rawResult.Split('.', ':').ToList<string>();
|
rawNumbers = rawResult.Split('.', ':').ToList<string>();
|
||||||
@@ -164,6 +179,9 @@ namespace OCR_Decode
|
|||||||
result += iter.GetText(PageIteratorLevel.Word);
|
result += iter.GetText(PageIteratorLevel.Word);
|
||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(result, "[^0-9A-Za-z]", "") + ".png");
|
||||||
|
|
||||||
page.Dispose();
|
page.Dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user