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