Removed useless Async methods
This commit is contained in:
@@ -18,9 +18,9 @@ namespace Test_Merge
|
|||||||
Reader = new Reader(configFile,screenshot, true);
|
Reader = new Reader(configFile,screenshot, true);
|
||||||
Storage = Reader.Storage;
|
Storage = Reader.Storage;
|
||||||
}
|
}
|
||||||
public async Task<int> Refresh()
|
public int Refresh()
|
||||||
{
|
{
|
||||||
LiveDriverDataLogs.Add(await Reader.Decode(Reader.MainZones, Reader.Drivers));
|
LiveDriverDataLogs.Add(Reader.Decode(Reader.MainZones, Reader.Drivers));
|
||||||
if (LiveDriverDataLogs.Count > 0)
|
if (LiveDriverDataLogs.Count > 0)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Test_Merge
|
|||||||
/// Method that will decode the content of the window
|
/// Method that will decode the content of the window
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override async Task<object> DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
int greenValue = GetGreenPixels();
|
int greenValue = GetGreenPixels();
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace Test_Merge
|
|||||||
/// Decodes the gap to leader using Tesseract OCR
|
/// Decodes the gap to leader using Tesseract OCR
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override async Task<object> DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Gap, Engine);
|
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.Gap, Engine);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace Test_Merge
|
|||||||
/// Decodes the lap time contained in the image using OCR Tesseract
|
/// Decodes the lap time contained in the image using OCR Tesseract
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The laptime in int (ms)</returns>
|
/// <returns>The laptime in int (ms)</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.LapTime, Engine);
|
int result = GetTimeFromPng(WindowImage, OcrImage.WindowType.LapTime, Engine);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ namespace Test_Merge
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="DriverList"></param>
|
/// <param name="DriverList"></param>
|
||||||
/// <returns>The driver name in string</returns>
|
/// <returns>The driver name in string</returns>
|
||||||
public override async Task<object> DecodePng(List<string> DriverList)
|
public override object DecodePng(List<string> DriverList)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
result = await GetStringFromPng(WindowImage, Engine);
|
result = GetStringFromPng(WindowImage, Engine);
|
||||||
|
|
||||||
if (!IsADriver(DriverList, result))
|
if (!IsADriver(DriverList, result))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace Test_Merge
|
|||||||
/// Decodes the position number using Tesseract OCR
|
/// Decodes the position number using Tesseract OCR
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The position of the pilot in int</returns>
|
/// <returns>The position of the pilot in int</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
string ocrResult = await GetStringFromPng(WindowImage, Engine, "0123456789");
|
string ocrResult = GetStringFromPng(WindowImage, Engine, "0123456789");
|
||||||
|
|
||||||
int position;
|
int position;
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace Test_Merge
|
|||||||
/// Decodes the sector
|
/// Decodes the sector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>the sector time in int (ms)</returns>
|
/// <returns>the sector time in int (ms)</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
int ocrResult = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector, Engine);
|
int ocrResult = GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector, Engine);
|
||||||
return ocrResult;
|
return ocrResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,22 +34,22 @@ namespace Test_Merge
|
|||||||
/// This will decode the content of the image
|
/// This will decode the content of the image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>And object containing what was on the image</returns>
|
/// <returns>And object containing what was on the image</returns>
|
||||||
public override async Task<object> DecodePng()
|
public override object DecodePng()
|
||||||
{
|
{
|
||||||
return await GetTyreInfos();
|
return GetTyreInfos();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method that will decode whats on the image and return the tyre infos it could manage to recover
|
/// Method that will decode whats on the image and return the tyre infos it could manage to recover
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A tyre object containing tyre infos</returns>
|
/// <returns>A tyre object containing tyre infos</returns>
|
||||||
private async Task<Tyre> GetTyreInfos()
|
private Tyre GetTyreInfos()
|
||||||
{
|
{
|
||||||
Bitmap tyreZone = GetSmallBitmapFromBigOne(WindowImage, FindTyreZone());
|
Bitmap tyreZone = GetSmallBitmapFromBigOne(WindowImage, FindTyreZone());
|
||||||
Tyre.Type type = Tyre.Type.Undefined;
|
Tyre.Type type = Tyre.Type.Undefined;
|
||||||
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(tyreZone));
|
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(tyreZone));
|
||||||
int laps = -1;
|
int laps = -1;
|
||||||
|
|
||||||
string number = await GetStringFromPng(tyreZone, Engine, "0123456789", OcrImage.WindowType.Tyre);
|
string number = GetStringFromPng(tyreZone, Engine, "0123456789", OcrImage.WindowType.Tyre);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
laps = Convert.ToInt32(number);
|
laps = Convert.ToInt32(number);
|
||||||
|
|||||||
+1
-1
@@ -103,7 +103,7 @@ namespace Test_Merge
|
|||||||
});
|
});
|
||||||
|
|
||||||
Wrapper.ChangeImage(screen);
|
Wrapper.ChangeImage(screen);
|
||||||
int errorCode = await Wrapper.Refresh();
|
int errorCode = Wrapper.Refresh();
|
||||||
|
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
// Task completed
|
// Task completed
|
||||||
|
|||||||
+29
-58
@@ -224,7 +224,7 @@ namespace Test_Merge
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idImage">The id of the image we are working with</param>
|
/// <param name="idImage">The id of the image we are working with</param>
|
||||||
/// <returns>a string representation of all the returns</returns>
|
/// <returns>a string representation of all the returns</returns>
|
||||||
public async Task<List<DriverData>> Decode(List<Zone> mainZones, List<string> drivers)
|
public List<DriverData> Decode(List<Zone> mainZones, List<string> drivers)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
List<DriverData> mainResults = new List<DriverData>();
|
List<DriverData> mainResults = new List<DriverData>();
|
||||||
@@ -240,70 +240,41 @@ namespace Test_Merge
|
|||||||
//Parallel.For(0, mainZones[mainZoneId].Zones.Count, async i =>
|
//Parallel.For(0, mainZones[mainZoneId].Zones.Count, async i =>
|
||||||
for (int i = 0; i < mainZones[mainZoneId].Zones.Count; i++)
|
for (int i = 0; i < mainZones[mainZoneId].Zones.Count; i++)
|
||||||
{
|
{
|
||||||
await Task.Run(async () =>
|
DriverData data = mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers));
|
||||||
|
mainResults.Add(data);
|
||||||
|
DriverDataLogs[i].Add(data);
|
||||||
|
|
||||||
|
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
|
||||||
{
|
{
|
||||||
DriverData data = await mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers));
|
//Tries to fix the tyres
|
||||||
|
if (data.CurrentTyre.NumberOfLaps > DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 3)
|
||||||
|
data.CurrentTyre.NumberOfLaps = DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 1;
|
||||||
|
|
||||||
//lock (lockObject)
|
//Checking if its a new lap
|
||||||
//{
|
//If the third sector is filled but it was'nt the last time, then it means that a new Lap has been started
|
||||||
mainResults.Add(data);
|
//Lap detection can be f***ed if the OCR takes so much time that an entire sector can be raced without us knowing.
|
||||||
DriverDataLogs[i].Add(data);
|
if (
|
||||||
|
DriverDataLogs[i][DriverDataLogs[i].Count - 1].Sector3 != 0
|
||||||
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
|
&& DriverDataLogs[i][DriverDataLogs[i].Count - 2].Sector3 == 0)
|
||||||
{
|
{
|
||||||
//Tries to fix the tyres
|
DriverData stats = DriverDataLogs[i][DriverDataLogs[i].Count - 2];
|
||||||
if (data.CurrentTyre.NumberOfLaps > DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 3)
|
DriverLaps[i]++;
|
||||||
data.CurrentTyre.NumberOfLaps = DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 1;
|
Storage.AddDriverStat(stats, DriverLaps[i]);
|
||||||
|
}
|
||||||
//Checking if its a new lap
|
//Checking if its a pitstop
|
||||||
//If the third sector is filled but it was'nt the last time, then it means that a new Lap has been started
|
//Forget this the best way to know if a tyre has been changed is if the number of laps is zero
|
||||||
//Lap detection can be f***ed if the OCR takes so much time that an entire sector can be raced without us knowing.
|
if (data.CurrentTyre.Coumpound != Tyre.Type.Undefined && data.CurrentTyre.NumberOfLaps == 0 && DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps != 0)
|
||||||
if (
|
{
|
||||||
DriverDataLogs[i][DriverDataLogs[i].Count - 1].Sector3 != 0
|
Storage.AddPitstop(data.Name, DriverLaps[i] - 1, data.CurrentTyre.Coumpound.ToString());
|
||||||
&& DriverDataLogs[i][DriverDataLogs[i].Count - 2].Sector3 == 0)
|
//Driver laps -1 because it would take AT LEAST one lap for this program to detect a pitstop
|
||||||
{
|
}
|
||||||
DriverData stats = DriverDataLogs[i][DriverDataLogs[i].Count - 2];
|
}
|
||||||
DriverLaps[i]++;
|
DriverDataLogs[i].Add(data);
|
||||||
Storage.AddDriverStat(stats, DriverLaps[i]);
|
|
||||||
}
|
|
||||||
//Checking if its a pitstop
|
|
||||||
//Forget this the best way to know if a tyre has been changed is if the number of laps is zero
|
|
||||||
if (data.CurrentTyre.Coumpound != Tyre.Type.Undefined && data.CurrentTyre.NumberOfLaps == 0 && DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps != 0)
|
|
||||||
{
|
|
||||||
Storage.AddPitstop(data.Name, DriverLaps[i] - 1, data.CurrentTyre.Coumpound.ToString());
|
|
||||||
//Driver laps -1 because it would take AT LEAST one lap for this program to detect a pitstop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DriverDataLogs[i].Add(data);
|
|
||||||
//}
|
|
||||||
});
|
|
||||||
}//);
|
}//);
|
||||||
break;
|
break;
|
||||||
//Next there could be a Title Zone and TrackInfoZone
|
//Next there could be a Title Zone and TrackInfoZone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Display
|
|
||||||
/*
|
|
||||||
int nullDrivers = 0;
|
|
||||||
foreach (DriverData driver in mainResults)
|
|
||||||
{
|
|
||||||
if (driver.Position == -1 && driver.LapTime == 0)
|
|
||||||
nullDrivers++;
|
|
||||||
result += driver.ToString();
|
|
||||||
result += Environment.NewLine;
|
|
||||||
}
|
|
||||||
//If 75% or more of the drivers cannot be decoded there must be a problem somewhere.
|
|
||||||
//Some can be because if they are out of the race usually the OCR returns -1 as the driver position
|
|
||||||
if (nullDrivers >= Convert.ToInt32((float)NUMBER_OF_DRIVERS / 4.0f * 3.0f) || mainResults.Count == 0)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return mainResults;
|
return mainResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace Test_Merge
|
|||||||
/// Method that will have to be used by the childrens to let the model make them decode the images they have
|
/// Method that will have to be used by the childrens to let the model make them decode the images they have
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns an object because we dont know what kind of return it will be</returns>
|
/// <returns>Returns an object because we dont know what kind of return it will be</returns>
|
||||||
public virtual async Task<Object> DecodePng()
|
public virtual Object DecodePng()
|
||||||
{
|
{
|
||||||
return "NaN";
|
return "NaN";
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ namespace Test_Merge
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="driverList">This is a list of the different possible drivers in the race. It should not be too big but NEVER be too short</param>
|
/// <param name="driverList">This is a list of the different possible drivers in the race. It should not be too big but NEVER be too short</param>
|
||||||
/// <returns>Returns an object because we dont know what kind of return it will be</returns>
|
/// <returns>Returns an object because we dont know what kind of return it will be</returns>
|
||||||
public virtual async Task<Object> DecodePng(List<string> driverList)
|
public virtual Object DecodePng(List<string> driverList)
|
||||||
{
|
{
|
||||||
return "NaN";
|
return "NaN";
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ namespace Test_Merge
|
|||||||
/// <param name="windowType">The type of window it is</param>
|
/// <param name="windowType">The type of window it is</param>
|
||||||
/// <param name="Engine">The Tesseract Engine</param>
|
/// <param name="Engine">The Tesseract Engine</param>
|
||||||
/// <returns>The time in milliseconds</returns>
|
/// <returns>The time in milliseconds</returns>
|
||||||
public static async Task<int> GetTimeFromPng(Bitmap image, OcrImage.WindowType windowType, TesseractEngine Engine)
|
public static int GetTimeFromPng(Bitmap image, OcrImage.WindowType windowType, TesseractEngine Engine)
|
||||||
{
|
{
|
||||||
//Kind of a big method but it has a lot of error handling and has to work with three special cases
|
//Kind of a big method but it has a lot of error handling and has to work with three special cases
|
||||||
string rawResult = "";
|
string rawResult = "";
|
||||||
@@ -149,8 +149,7 @@ namespace Test_Merge
|
|||||||
|
|
||||||
var tessImage = Pix.LoadFromMemory(ImageToByte(enhancedImage));
|
var tessImage = Pix.LoadFromMemory(ImageToByte(enhancedImage));
|
||||||
|
|
||||||
Page page = null;
|
Page page = Engine.Process(tessImage);
|
||||||
await Task.Run(()=> page = Engine.Process(tessImage));
|
|
||||||
Graphics g = Graphics.FromImage(enhancedImage);
|
Graphics g = Graphics.FromImage(enhancedImage);
|
||||||
// Get the iterator for the page layout
|
// Get the iterator for the page layout
|
||||||
using (var iter = page.GetIterator())
|
using (var iter = page.GetIterator())
|
||||||
@@ -554,7 +553,7 @@ namespace Test_Merge
|
|||||||
/// <param name="allowedChars">The list of allowed chars</param>
|
/// <param name="allowedChars">The list of allowed chars</param>
|
||||||
/// <param name="windowType">The type of window the text is on. Depending on the context the OCR will behave differently</param>
|
/// <param name="windowType">The type of window the text is on. Depending on the context the OCR will behave differently</param>
|
||||||
/// <returns>the string it found</returns>
|
/// <returns>the string it found</returns>
|
||||||
public static async Task<string> GetStringFromPng(Bitmap image, TesseractEngine Engine, string allowedChars = "", OcrImage.WindowType windowType = OcrImage.WindowType.Text)
|
public static string GetStringFromPng(Bitmap image, TesseractEngine Engine, string allowedChars = "", OcrImage.WindowType windowType = OcrImage.WindowType.Text)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -86,7 +86,7 @@ namespace Test_Merge
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="driverList">A list of all the driver in the race to help with text recognition</param>
|
/// <param name="driverList">A list of all the driver in the race to help with text recognition</param>
|
||||||
/// <returns>A driver data object that contains all the infos about a driver</returns>
|
/// <returns>A driver data object that contains all the infos about a driver</returns>
|
||||||
public virtual async Task<DriverData> Decode(List<string> driverList)
|
public virtual DriverData Decode(List<string> driverList)
|
||||||
{
|
{
|
||||||
int sectorCount = 0;
|
int sectorCount = 0;
|
||||||
DriverData result = new DriverData();
|
DriverData result = new DriverData();
|
||||||
@@ -94,27 +94,27 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
// A switch would be prettier but I dont think its supported in this C# version
|
// A switch would be prettier but I dont think its supported in this C# version
|
||||||
if (w is DriverNameWindow)
|
if (w is DriverNameWindow)
|
||||||
result.Name = (string)await (w as DriverNameWindow).DecodePng(driverList);
|
result.Name = (string)(w as DriverNameWindow).DecodePng(driverList);
|
||||||
if (w is DriverDrsWindow)
|
if (w is DriverDrsWindow)
|
||||||
result.DRS = (bool)await (w as DriverDrsWindow).DecodePng();
|
result.DRS = (bool)(w as DriverDrsWindow).DecodePng();
|
||||||
if (w is DriverGapToLeaderWindow)
|
if (w is DriverGapToLeaderWindow)
|
||||||
result.GapToLeader = (int)await (w as DriverGapToLeaderWindow).DecodePng();
|
result.GapToLeader = (int)(w as DriverGapToLeaderWindow).DecodePng();
|
||||||
if (w is DriverLapTimeWindow)
|
if (w is DriverLapTimeWindow)
|
||||||
result.LapTime = (int)await (w as DriverLapTimeWindow).DecodePng();
|
result.LapTime = (int)(w as DriverLapTimeWindow).DecodePng();
|
||||||
if (w is DriverPositionWindow)
|
if (w is DriverPositionWindow)
|
||||||
result.Position = (int)await (w as DriverPositionWindow).DecodePng();
|
result.Position = (int)(w as DriverPositionWindow).DecodePng();
|
||||||
if (w is DriverSectorWindow)
|
if (w is DriverSectorWindow)
|
||||||
{
|
{
|
||||||
sectorCount++;
|
sectorCount++;
|
||||||
if (sectorCount == 1)
|
if (sectorCount == 1)
|
||||||
result.Sector1 = (int)await (w as DriverSectorWindow).DecodePng();
|
result.Sector1 = (int)(w as DriverSectorWindow).DecodePng();
|
||||||
if (sectorCount == 2)
|
if (sectorCount == 2)
|
||||||
result.Sector2 = (int)await (w as DriverSectorWindow).DecodePng();
|
result.Sector2 = (int)(w as DriverSectorWindow).DecodePng();
|
||||||
if (sectorCount == 3)
|
if (sectorCount == 3)
|
||||||
result.Sector3 = (int)await (w as DriverSectorWindow).DecodePng();
|
result.Sector3 = (int)(w as DriverSectorWindow).DecodePng();
|
||||||
}
|
}
|
||||||
if (w is DriverTyresWindow)
|
if (w is DriverTyresWindow)
|
||||||
result.CurrentTyre = (Tyre)await (w as DriverTyresWindow).DecodePng();
|
result.CurrentTyre = (Tyre)(w as DriverTyresWindow).DecodePng();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user