Now everything has been converted to asynchronus

This commit is contained in:
2023-04-11 09:40:21 +02:00
parent e278a1c006
commit 8796fed916
13 changed files with 37 additions and 37 deletions
+1 -1
View File
@@ -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();
+2 -2
View File
@@ -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;
}
}
+2 -2
View File
@@ -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;
}
}
+2 -2
View File
@@ -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))
{
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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;
}
}
+2 -2
View File
@@ -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;
}
}
+2 -2
View File
@@ -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;
}
}
+5 -6
View File
@@ -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
View File
@@ -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;
+8 -7
View File
@@ -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)
+4 -4
View File
@@ -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
View File
@@ -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;