Fixed the ridiculus times where the ':' in laptimes was interpreted as a number
This commit is contained in:
@@ -75,7 +75,7 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
laps = -1;
|
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");
|
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
||||||
|
|||||||
+18
-18
@@ -35,30 +35,24 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
case WindowType.LapTime:
|
case WindowType.LapTime:
|
||||||
result = Tresholding(result, 185);
|
result = Tresholding(result, 185);
|
||||||
result = Resize(result);
|
result = Resize(result,2);
|
||||||
result = Resize(result);
|
|
||||||
result = Dilatation(result,1);
|
result = Dilatation(result,1);
|
||||||
result = Erode(result,1);
|
result = Erode(result,1);
|
||||||
break;
|
break;
|
||||||
case WindowType.Text:
|
case WindowType.Text:
|
||||||
result = Grayscale(result);
|
|
||||||
result = InvertColors(result);
|
result = InvertColors(result);
|
||||||
result = Tresholding(result, 165);
|
result = Tresholding(result, 165);
|
||||||
result = Resize(result);
|
result = Resize(result,2);
|
||||||
result = Dilatation(result, 1);
|
result = Dilatation(result, 1);
|
||||||
break;
|
break;
|
||||||
case WindowType.Tyre:
|
case WindowType.Tyre:
|
||||||
//result = RemoveBG(result);
|
|
||||||
result = RemoveUseless(result);
|
result = RemoveUseless(result);
|
||||||
result = Resize(result);
|
result = Resize(result,4);
|
||||||
result = Resize(result);
|
|
||||||
result = Resize(result);
|
|
||||||
result = Dilatation(result, 1);
|
result = Dilatation(result, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result = Tresholding(result, 165);
|
result = Tresholding(result, 165);
|
||||||
result = Resize(result);
|
result = Resize(result,4);
|
||||||
result = Resize(result);
|
|
||||||
result = Erode(result, 1);
|
result = Erode(result, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -106,10 +100,13 @@ namespace OCR_Decode
|
|||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
byte* ptr = (byte*)bmpData.Scan0.ToPointer();
|
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);
|
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);
|
byte* pixel = currentLine + (x * bytesPerPixel);
|
||||||
|
|
||||||
@@ -122,7 +119,7 @@ namespace OCR_Decode
|
|||||||
|
|
||||||
pixel[0] = pixel[1] = pixel[2] = (byte)value;
|
pixel[0] = pixel[1] = pixel[2] = (byte)value;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
bmp.UnlockBits(bmpData);
|
bmp.UnlockBits(bmpData);
|
||||||
|
|
||||||
@@ -269,10 +266,13 @@ namespace OCR_Decode
|
|||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
byte* ptr = (byte*)bmpData.Scan0.ToPointer();
|
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);
|
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);
|
byte* pixel = currentLine + (x * bytesPerPixel);
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ namespace OCR_Decode
|
|||||||
totR += pixel[2];
|
totR += pixel[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
bmp.UnlockBits(bmpData);
|
bmp.UnlockBits(bmpData);
|
||||||
|
|
||||||
@@ -329,10 +329,10 @@ namespace OCR_Decode
|
|||||||
Bitmap output = filter.Apply(input);
|
Bitmap output = filter.Apply(input);
|
||||||
return output;
|
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
|
// 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
|
// Create a Graphics object to draw the resized image
|
||||||
using (var graphics = Graphics.FromImage(resultBitmap))
|
using (var graphics = Graphics.FromImage(resultBitmap))
|
||||||
|
|||||||
+16
-3
@@ -103,8 +103,6 @@ namespace OCR_Decode
|
|||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
}
|
}
|
||||||
|
|
||||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
|
|
||||||
|
|
||||||
List<string> rawNumbers;
|
List<string> rawNumbers;
|
||||||
|
|
||||||
//In the gaps we can find '+' but we dont care about it its redondant
|
//In the gaps we can find '+' but we dont care about it its redondant
|
||||||
@@ -127,6 +125,19 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
//ss:ms
|
//ss:ms
|
||||||
result = (Convert.ToInt32(rawNumbers[0]) * 1000) + Convert.ToInt32(rawNumbers[1]);
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -149,6 +160,7 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
|
||||||
page.Dispose();
|
page.Dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -170,7 +182,7 @@ namespace OCR_Decode
|
|||||||
result += iter.GetText(PageIteratorLevel.Word);
|
result += iter.GetText(PageIteratorLevel.Word);
|
||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (allowedChars.Contains("S"))
|
if (allowedChars.Contains("S"))
|
||||||
{
|
{
|
||||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + result +".png");
|
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + result +".png");
|
||||||
@@ -179,6 +191,7 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + result +".png");
|
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + result +".png");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
page.Dispose();
|
page.Dispose();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user