Fixed the ridiculus times where the ':' in laptimes was interpreted as a number

This commit is contained in:
2023-04-13 07:30:05 +02:00
parent dbda3d3788
commit 5f8f1f0704
3 changed files with 35 additions and 22 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ namespace OCR_Decode
{
laps = -1;
}
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone)));
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone,2)));
}
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
+18 -18
View File
@@ -35,30 +35,24 @@ namespace OCR_Decode
{
case WindowType.LapTime:
result = Tresholding(result, 185);
result = Resize(result);
result = Resize(result);
result = Resize(result,2);
result = Dilatation(result,1);
result = Erode(result,1);
break;
case WindowType.Text:
result = Grayscale(result);
result = InvertColors(result);
result = Tresholding(result, 165);
result = Resize(result);
result = Resize(result,2);
result = Dilatation(result, 1);
break;
case WindowType.Tyre:
//result = RemoveBG(result);
result = RemoveUseless(result);
result = Resize(result);
result = Resize(result);
result = Resize(result);
result = Resize(result,4);
result = Dilatation(result, 1);
break;
default:
result = Tresholding(result, 165);
result = Resize(result);
result = Resize(result);
result = Resize(result,4);
result = Erode(result, 1);
break;
}
@@ -106,10 +100,13 @@ namespace OCR_Decode
unsafe
{
byte* ptr = (byte*)bmpData.Scan0.ToPointer();
for (int y = 0; y < bmp.Height; y++)
int bmpHeight = bmp.Height;
int bmpWidth = bmp.Width;
Parallel.For(0, bmpHeight, y =>
//for (int y = 0; y < bmpHeight; y++)
{
byte* currentLine = ptr + (y * bmpData.Stride);
for (int x = 0; x < bmp.Width; x++)
for (int x = 0; x < bmpWidth; x++)
{
byte* pixel = currentLine + (x * bytesPerPixel);
@@ -122,7 +119,7 @@ namespace OCR_Decode
pixel[0] = pixel[1] = pixel[2] = (byte)value;
}
}
});
}
bmp.UnlockBits(bmpData);
@@ -269,10 +266,13 @@ namespace OCR_Decode
unsafe
{
byte* ptr = (byte*)bmpData.Scan0.ToPointer();
for (int y = 0; y < bmp.Height; y++)
int bmpHeight = bmp.Height;
int bmpWidth = bmp.Width;
Parallel.For(0,bmpHeight,y=>
//for (int y = 0; y < bmp.Height; y++)
{
byte* currentLine = ptr + (y * bmpData.Stride);
for (int x = 0; x < bmp.Width; x++)
for (int x = 0; x < bmpWidth; x++)
{
byte* pixel = currentLine + (x * bytesPerPixel);
@@ -290,7 +290,7 @@ namespace OCR_Decode
totR += pixel[2];
}
}
}
});
}
bmp.UnlockBits(bmpData);
@@ -329,10 +329,10 @@ namespace OCR_Decode
Bitmap output = filter.Apply(input);
return output;
}
public static Bitmap Resize(Bitmap sourceBitmap)
public static Bitmap Resize(Bitmap sourceBitmap,int amount)
{
// Create a new Bitmap object to hold the resized image
var resultBitmap = new Bitmap(sourceBitmap.Width * 2, sourceBitmap.Height * 2);
var resultBitmap = new Bitmap(sourceBitmap.Width * amount, sourceBitmap.Height * amount);
// Create a Graphics object to draw the resized image
using (var graphics = Graphics.FromImage(resultBitmap))
+16 -3
View File
@@ -103,8 +103,6 @@ namespace OCR_Decode
} while (iter.Next(PageIteratorLevel.Word));
}
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
List<string> rawNumbers;
//In the gaps we can find '+' but we dont care about it its redondant
@@ -127,6 +125,19 @@ namespace OCR_Decode
{
//ss:ms
result = (Convert.ToInt32(rawNumbers[0]) * 1000) + Convert.ToInt32(rawNumbers[1]);
//1239
//931
if (result > 999999)
{
//We know that we have way too much seconds to make a minut
//Its usually because the ":" have been interpreted as a number
int minuts = (int)(rawNumbers[0][0] - '0');
// rawNumbers[0][1] should contain the : that has been mistaken
int seconds = Convert.ToInt32(rawNumbers[0][2].ToString() + rawNumbers[0][3].ToString());
int ms = Convert.ToInt32(rawNumbers[1]);
result = (Convert.ToInt32(minuts) * 1000 * 60) + (Convert.ToInt32(seconds) * 1000) + Convert.ToInt32(ms);
}
}
else
{
@@ -149,6 +160,7 @@ namespace OCR_Decode
}
}
}
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
page.Dispose();
return result;
}
@@ -170,7 +182,7 @@ namespace OCR_Decode
result += iter.GetText(PageIteratorLevel.Word);
} while (iter.Next(PageIteratorLevel.Word));
}
/*
if (allowedChars.Contains("S"))
{
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + result +".png");
@@ -179,6 +191,7 @@ namespace OCR_Decode
{
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + result +".png");
}
*/
page.Dispose();
return result;