Now everything has been converted to asynchronus
This commit is contained in:
@@ -18,7 +18,7 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "DRS";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
bool result = false;
|
||||
int greenValue = GetGreenPixels();
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Gap to leader";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.Gap);
|
||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Gap);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Lap time";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
int result = GetTimeFromPng(WindowImage,OcrImage.WindowType.LapTime);
|
||||
int result = await GetTimeFromPng(WindowImage,OcrImage.WindowType.LapTime);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Name";
|
||||
}
|
||||
public override object DecodePng(List<string> DriverList)
|
||||
public override async Task<object> DecodePng(List<string> DriverList)
|
||||
{
|
||||
string result = "";
|
||||
result = GetStringFromPng(WindowImage);
|
||||
result = await GetStringFromPng(WindowImage);
|
||||
|
||||
if (!IsADriver(DriverList, result))
|
||||
{
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Position";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
string result = GetStringFromPng(WindowImage,"0123456789");
|
||||
string result = await GetStringFromPng(WindowImage,"0123456789");
|
||||
|
||||
int position;
|
||||
try
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Sector 1";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Sector 2";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Sector 3";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
int result = GetTimeFromPng(WindowImage,OcrImage.WindowType.Sector);
|
||||
int result = await GetTimeFromPng(WindowImage,OcrImage.WindowType.Sector);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,12 @@ namespace OCR_Decode
|
||||
{
|
||||
Name = "Tyres";
|
||||
}
|
||||
public override object DecodePng()
|
||||
public override async Task<object> DecodePng()
|
||||
{
|
||||
//WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "testTyres" + rnd.Next(0, 1000) + ".png");
|
||||
|
||||
return GetTyreInfos();
|
||||
return await GetTyreInfos();
|
||||
}
|
||||
private Tyre GetTyreInfos()
|
||||
private async Task<Tyre> GetTyreInfos()
|
||||
{
|
||||
Bitmap tyreZone = GetSmallBitmapFromBigOne(WindowImage, FindTyreZone());
|
||||
|
||||
@@ -37,7 +36,7 @@ namespace OCR_Decode
|
||||
int laps = -1;
|
||||
|
||||
//MHIWsmhiw so we can detect Soft Medium Hard Inters and Wet tyres
|
||||
string text = GetStringFromPng(tyreZone, "SMHIW", OcrImage.WindowType.Tyre);
|
||||
string text = await GetStringFromPng(tyreZone, "SMHIW", OcrImage.WindowType.Tyre);
|
||||
if (text.Length == 1 && text != "")
|
||||
{
|
||||
//We found a tire letter
|
||||
@@ -67,7 +66,7 @@ namespace OCR_Decode
|
||||
}
|
||||
else
|
||||
{
|
||||
string number = GetStringFromPng(tyreZone, "0123456789", OcrImage.WindowType.Tyre);
|
||||
string number = await GetStringFromPng(tyreZone, "0123456789", OcrImage.WindowType.Tyre);
|
||||
try
|
||||
{
|
||||
laps = Convert.ToInt32(number);
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ namespace OCR_Decode
|
||||
|
||||
RefreshUi();
|
||||
}
|
||||
private void RefreshUi()
|
||||
private async void RefreshUi()
|
||||
{
|
||||
|
||||
tbxResult.Text = "";
|
||||
@@ -45,7 +45,7 @@ namespace OCR_Decode
|
||||
int DrawMS = (int)stopWatch.ElapsedMilliseconds;
|
||||
|
||||
stopWatch.Restart();
|
||||
tbxResult.Text = Reader.Decode(pageNmbr);
|
||||
tbxResult.Text = await Reader.Decode(pageNmbr);
|
||||
stopWatch.Stop();
|
||||
|
||||
int OcrMS = (int)stopWatch.ElapsedMilliseconds;
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace OCR_Decode
|
||||
}
|
||||
}
|
||||
}
|
||||
public string Decode(int idImage)
|
||||
public async Task<string> Decode(int idImage)
|
||||
{
|
||||
string result = "";
|
||||
ChangeImage(idImage);
|
||||
@@ -183,10 +183,11 @@ namespace OCR_Decode
|
||||
{
|
||||
case 0:
|
||||
//Main Zone
|
||||
//Parallel.ForEach(MainZones[mainZoneId].Zones, z =>
|
||||
foreach (Zone z in MainZones[mainZoneId].Zones)
|
||||
{
|
||||
mainResults.Add(z.Decode(Drivers));
|
||||
}
|
||||
mainResults.Add(await z.Decode(Drivers));
|
||||
}//);
|
||||
break;
|
||||
//Next there will be the title and laps added
|
||||
}
|
||||
@@ -276,11 +277,11 @@ namespace OCR_Decode
|
||||
int count = 0;
|
||||
foreach (Zone zz in z.Zones)
|
||||
{
|
||||
string driverFolder = DEBUG_DUMP_FOLDER + "driver" + count + "\\";
|
||||
if (!Directory.Exists(driverFolder))
|
||||
Directory.CreateDirectory(driverFolder);
|
||||
//string driverFolder = DEBUG_DUMP_FOLDER + "driver" + count + "\\";
|
||||
//if (!Directory.Exists(driverFolder))
|
||||
//Directory.CreateDirectory(driverFolder);
|
||||
|
||||
zz.ZoneImage.Save(driverFolder + "FullImage.png");
|
||||
//zz.ZoneImage.Save(driverFolder + "FullImage.png");
|
||||
|
||||
g.DrawRectangle(Pens.Red, z.Bounds);
|
||||
foreach (Window w in zz.Windows)
|
||||
|
||||
@@ -44,11 +44,11 @@ namespace OCR_Decode
|
||||
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||
}
|
||||
}
|
||||
public virtual Object DecodePng()
|
||||
public virtual async Task<Object> DecodePng()
|
||||
{
|
||||
return "NaN";
|
||||
}
|
||||
public virtual Object DecodePng(List<string> drivers)
|
||||
public virtual async Task<Object> DecodePng(List<string> drivers)
|
||||
{
|
||||
return "NaN";
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace OCR_Decode
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
public static int GetTimeFromPng(Bitmap wImage,OcrImage.WindowType type)
|
||||
public static async Task<int> GetTimeFromPng(Bitmap wImage,OcrImage.WindowType type)
|
||||
{
|
||||
string rawResult = "";
|
||||
int result = 0;
|
||||
@@ -156,7 +156,7 @@ namespace OCR_Decode
|
||||
page.Dispose();
|
||||
return result;
|
||||
}
|
||||
public static string GetStringFromPng(Bitmap image,string allowedChars = "",OcrImage.WindowType windowType = OcrImage.WindowType.Text)
|
||||
public static async Task<string> GetStringFromPng(Bitmap image,string allowedChars = "",OcrImage.WindowType windowType = OcrImage.WindowType.Text)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
|
||||
+3
-3
@@ -62,18 +62,18 @@ namespace OCR_Decode
|
||||
{
|
||||
Windows.Add(window);
|
||||
}
|
||||
public virtual List<Object> Decode(List<string> drivers)
|
||||
public virtual async Task<List<Object>> Decode(List<string> drivers)
|
||||
{
|
||||
List<Object> result = new List<Object>();
|
||||
foreach (Window w in Windows)
|
||||
{
|
||||
if (w is DriverNameWindow)
|
||||
{
|
||||
result.Add((w as DriverNameWindow).DecodePng(drivers));
|
||||
result.Add(await (w as DriverNameWindow).DecodePng(drivers));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(w.DecodePng());
|
||||
result.Add(await w.DecodePng());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user