Improved processing quality of the tyres number of laps
This commit is contained in:
@@ -32,8 +32,6 @@ namespace OCR_Decode
|
||||
private async Task<Tyre> GetTyreInfos()
|
||||
{
|
||||
Bitmap tyreZone = GetSmallBitmapFromBigOne(WindowImage, FindTyreZone());
|
||||
|
||||
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "ZONE" + ".png");
|
||||
Tyre.Type type = Tyre.Type.Undefined;
|
||||
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone, 2)));
|
||||
int laps = -1;
|
||||
@@ -45,7 +43,8 @@ namespace OCR_Decode
|
||||
}
|
||||
catch
|
||||
{
|
||||
//We could not convert the number
|
||||
//We could not convert the number so its a letter so its 0 laps old
|
||||
laps = 0;
|
||||
}
|
||||
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
||||
return new Tyre(type, laps);
|
||||
|
||||
+24
-16
@@ -15,6 +15,7 @@ namespace OCR_Decode
|
||||
public class OcrImage
|
||||
{
|
||||
Bitmap InputImage;
|
||||
Random rnd = new Random();
|
||||
public enum WindowType
|
||||
{
|
||||
LapTime,
|
||||
@@ -30,29 +31,31 @@ namespace OCR_Decode
|
||||
public Bitmap Enhance(WindowType type = WindowType.Text)
|
||||
{
|
||||
Bitmap result = (Bitmap)InputImage.Clone();
|
||||
|
||||
int salt = rnd.Next(0, 10000);
|
||||
switch (type)
|
||||
{
|
||||
case WindowType.LapTime:
|
||||
result = Tresholding(result, 185);
|
||||
result = Resize(result,2);
|
||||
result = Dilatation(result,1);
|
||||
result = Erode(result,1);
|
||||
result = Resize(result, 2);
|
||||
result = Dilatation(result, 1);
|
||||
result = Erode(result, 1);
|
||||
break;
|
||||
case WindowType.Text:
|
||||
result = InvertColors(result);
|
||||
result = Tresholding(result, 165);
|
||||
result = Resize(result,2);
|
||||
result = Resize(result, 2);
|
||||
result = Dilatation(result, 1);
|
||||
break;
|
||||
case WindowType.Tyre:
|
||||
//result.Save(Reader.DEBUG_DUMP_FOLDER + "tyreBefore_" + salt + ".png");
|
||||
result = RemoveUseless(result);
|
||||
result = Resize(result,4);
|
||||
result = Resize(result, 4);
|
||||
result = Dilatation(result, 1);
|
||||
//result.Save(Reader.DEBUG_DUMP_FOLDER + "tyreAfter_" + salt + ".png");
|
||||
break;
|
||||
default:
|
||||
result = Tresholding(result, 165);
|
||||
result = Resize(result,4);
|
||||
result = Resize(result, 4);
|
||||
result = Erode(result, 1);
|
||||
break;
|
||||
}
|
||||
@@ -162,7 +165,7 @@ namespace OCR_Decode
|
||||
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||
BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat);
|
||||
int bytesPerPixel = Bitmap.GetPixelFormatSize(bmp.PixelFormat) / 8;
|
||||
|
||||
Color limitColor = Color.FromArgb(0x50,0x50,0x50);
|
||||
|
||||
byte* ptr = (byte*)bmpData.Scan0.ToPointer();
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
@@ -181,13 +184,17 @@ namespace OCR_Decode
|
||||
int G = pixel[1];
|
||||
int R = pixel[2];
|
||||
|
||||
if (fromBorder && B < 0x10 && G < 0x10 && R < 0x10)
|
||||
if (fromBorder && B < limitColor.B && G < limitColor.G && R < limitColor.R)
|
||||
{
|
||||
pixelsToRemove.Add(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fromBorder)
|
||||
{
|
||||
fromBorder = false;
|
||||
pixelsToRemove.Add(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
fromBorder = true;
|
||||
@@ -199,13 +206,17 @@ namespace OCR_Decode
|
||||
int G = pixel[1];
|
||||
int R = pixel[2];
|
||||
|
||||
if (fromBorder && B < 0x10 && G < 0x10 && R < 0x10)
|
||||
if (fromBorder && B < limitColor.B && G < limitColor.G && R < limitColor.R)
|
||||
{
|
||||
pixelsToRemove.Add(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fromBorder)
|
||||
{
|
||||
fromBorder = false;
|
||||
pixelsToRemove.Add(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +232,6 @@ namespace OCR_Decode
|
||||
|
||||
|
||||
//NOW REMOVING THE COLOR
|
||||
Color limitColor = Color.FromArgb(0x50, 0x50, 0x50);
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
{
|
||||
byte* currentLine = ptr + (y * bmpData.Stride);
|
||||
@@ -235,7 +245,7 @@ namespace OCR_Decode
|
||||
|
||||
//We remove the background pixels
|
||||
|
||||
if (R >= limitColor.R || G >= limitColor.G || B >= limitColor.B)
|
||||
if (R >= limitColor.R + 20 || G >= limitColor.G + 20 || B >= limitColor.B + 20)
|
||||
{
|
||||
pixel[0] = 0xFF;
|
||||
pixel[1] = 0xFF;
|
||||
@@ -244,8 +254,6 @@ namespace OCR_Decode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bmp.UnlockBits(bmpData);
|
||||
|
||||
return bmp;
|
||||
@@ -268,7 +276,7 @@ namespace OCR_Decode
|
||||
byte* ptr = (byte*)bmpData.Scan0.ToPointer();
|
||||
int bmpHeight = bmp.Height;
|
||||
int bmpWidth = bmp.Width;
|
||||
Parallel.For(0,bmpHeight,y=>
|
||||
Parallel.For(0, bmpHeight, y =>
|
||||
//for (int y = 0; y < bmp.Height; y++)
|
||||
{
|
||||
byte* currentLine = ptr + (y * bmpData.Stride);
|
||||
@@ -329,7 +337,7 @@ namespace OCR_Decode
|
||||
Bitmap output = filter.Apply(input);
|
||||
return output;
|
||||
}
|
||||
public static Bitmap Resize(Bitmap sourceBitmap,int amount)
|
||||
public static Bitmap Resize(Bitmap sourceBitmap, int amount)
|
||||
{
|
||||
// Create a new Bitmap object to hold the resized image
|
||||
var resultBitmap = new Bitmap(sourceBitmap.Width * amount, sourceBitmap.Height * amount);
|
||||
|
||||
Reference in New Issue
Block a user