Compare commits
6 Commits
0.1
...
bc18274762
| Author | SHA1 | Date | |
|---|---|---|---|
| bc18274762 | |||
| 0c84d468b2 | |||
| fde3bcaae6 | |||
| 8796fed916 | |||
| e278a1c006 | |||
| 4d03070849 |
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
public class DriverData
|
||||
{
|
||||
public bool DRS; //True = Drs is opened
|
||||
public int GapToLeader; //In ms
|
||||
public int LapTime; //In ms
|
||||
public string Name; //Ex: LECLERC
|
||||
public int Position; //Ex: 1
|
||||
public int Sector1; //in ms
|
||||
public int Sector2; //in ms
|
||||
public int Sector3; //in ms
|
||||
public Tyre CurrentTyre;//Ex Soft 11 laps
|
||||
|
||||
public DriverData(bool dRS, int gapToLeader, int lapTime, string name, int position, int sector1, int sector2, int sector3, Tyre tyre)
|
||||
{
|
||||
DRS = dRS;
|
||||
GapToLeader = gapToLeader;
|
||||
LapTime = lapTime;
|
||||
Name = name;
|
||||
Position = position;
|
||||
Sector1 = sector1;
|
||||
Sector2 = sector2;
|
||||
Sector3 = sector3;
|
||||
CurrentTyre = tyre;
|
||||
}
|
||||
public DriverData()
|
||||
{
|
||||
DRS = false;
|
||||
GapToLeader = -1;
|
||||
LapTime = -1;
|
||||
Name = "Unknown";
|
||||
Position = -1;
|
||||
Sector1 = -1;
|
||||
Sector2 = -1;
|
||||
Sector3 = -1;
|
||||
CurrentTyre = new Tyre(Tyre.Type.Undefined,-1);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
string result = "";
|
||||
|
||||
//Position
|
||||
result += "Position : " + Position +Environment.NewLine;
|
||||
//Gap
|
||||
result += "Gap to leader : " + Reader.ConvertMsToTime(GapToLeader) + Environment.NewLine;
|
||||
//LapTime
|
||||
result += "Lap time : " + Reader.ConvertMsToTime(LapTime) + Environment.NewLine;
|
||||
//DRS
|
||||
result += "DRS : " + DRS + Environment.NewLine;
|
||||
//Tyres
|
||||
result += "Uses " + CurrentTyre.Coumpound + " tyre " + CurrentTyre.NumberOfLaps + " laps old" + Environment.NewLine;
|
||||
//Name
|
||||
result += "Driver name : " + Name +Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 1 : " + Reader.ConvertMsToTime(Sector1) + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 2 : " + Reader.ConvertMsToTime(Sector2) + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 3 : " + Reader.ConvertMsToTime(Sector3) + Environment.NewLine;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public struct Tyre
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
Soft,
|
||||
Medium,
|
||||
Hard,
|
||||
Inter,
|
||||
Wet,
|
||||
Undefined
|
||||
}
|
||||
public Type Coumpound;
|
||||
public int NumberOfLaps;
|
||||
public Tyre(Type type, int laps)
|
||||
{
|
||||
Coumpound = type;
|
||||
NumberOfLaps = laps;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
@@ -28,7 +28,7 @@ namespace OCR_Decode
|
||||
if (greenValue > EmptyDrsGreenValue + EmptyDrsGreenValue / 100 * 30)
|
||||
result = true;
|
||||
|
||||
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "DRS" + result + ".png");
|
||||
//WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "DRS" + result + ".png");
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -68,7 +68,6 @@ namespace OCR_Decode
|
||||
}
|
||||
public Rectangle GetBox()
|
||||
{
|
||||
|
||||
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
|
||||
Engine.SetVariable("tessedit_char_whitelist", "");
|
||||
Page page = Engine.Process(tessImage);
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -13,9 +14,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, Engine);
|
||||
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,Engine);
|
||||
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,Engine);
|
||||
|
||||
if (!IsADriver(DriverList, result))
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -13,10 +14,10 @@ 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,Engine, "0123456789");
|
||||
|
||||
int position;
|
||||
try
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace OCR_Decode
|
||||
catch
|
||||
{
|
||||
position = -1;
|
||||
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "FailedPosition"+".png");
|
||||
//WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "FailedPosition" + ".png");
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -13,9 +14,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, Engine);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -13,9 +14,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,Engine);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -13,9 +15,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,Engine);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -12,32 +13,30 @@ namespace OCR_Decode
|
||||
{
|
||||
private static Random rnd = new Random();
|
||||
|
||||
public static Color SOFT_TYRE_COLOR = Color.FromArgb(0xff,0x00,0x00);
|
||||
public static Color MEDIUM_TYRE_COLOR = Color.FromArgb(0xf5,0xbf,0x00);
|
||||
public static Color HARD_TYRE_COLOR = Color.FromArgb(0xd9,0xd8,0xd4);
|
||||
public static Color INTER_TYRE_COLOR = Color.FromArgb(0x00,0xa4,0x2e);
|
||||
public static Color WET_TYRE_COLOR = Color.FromArgb(0x27,0x60,0xa6);
|
||||
public static Color SOFT_TYRE_COLOR = Color.FromArgb(0xff, 0x00, 0x00);
|
||||
public static Color MEDIUM_TYRE_COLOR = Color.FromArgb(0xf5, 0xbf, 0x00);
|
||||
public static Color HARD_TYRE_COLOR = Color.FromArgb(0xd9, 0xd8, 0xd4);
|
||||
public static Color INTER_TYRE_COLOR = Color.FromArgb(0x00, 0xa4, 0x2e);
|
||||
public static Color WET_TYRE_COLOR = Color.FromArgb(0x27, 0x60, 0xa6);
|
||||
|
||||
public DriverTyresWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
|
||||
{
|
||||
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());
|
||||
|
||||
tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "ZONE" + ".png");
|
||||
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "ZONE" + ".png");
|
||||
Tyre.Type type = Tyre.Type.Undefined;
|
||||
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,Engine, "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, Engine, "0123456789", OcrImage.WindowType.Tyre);
|
||||
try
|
||||
{
|
||||
laps = Convert.ToInt32(number);
|
||||
@@ -79,32 +78,32 @@ namespace OCR_Decode
|
||||
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone)));
|
||||
}
|
||||
|
||||
tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
||||
return new Tyre(type,laps);
|
||||
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
||||
return new Tyre(type, laps);
|
||||
}
|
||||
private Rectangle FindTyreZone()
|
||||
{
|
||||
Bitmap bmp = WindowImage;
|
||||
int currentPosition = bmp.Width;
|
||||
int height = bmp.Height / 2;
|
||||
Color limitColor = Color.FromArgb(0x50,0x50,0x50);
|
||||
Color currentColor = Color.FromArgb(0,0,0);
|
||||
Color limitColor = Color.FromArgb(0x50, 0x50, 0x50);
|
||||
Color currentColor = Color.FromArgb(0, 0, 0);
|
||||
|
||||
Size newWindowSize = new Size(bmp.Height -Convert.ToInt32((float)bmp.Height / 100f * 25f),bmp.Height - Convert.ToInt32((float)bmp.Height / 100f * 35f));
|
||||
Size newWindowSize = new Size(bmp.Height - Convert.ToInt32((float)bmp.Height / 100f * 25f), bmp.Height - Convert.ToInt32((float)bmp.Height / 100f * 35f));
|
||||
|
||||
while(currentColor.R <= limitColor.R && currentColor.G <= limitColor.G && currentColor.B <= limitColor.B && currentPosition > 0)
|
||||
while (currentColor.R <= limitColor.R && currentColor.G <= limitColor.G && currentColor.B <= limitColor.B && currentPosition > 0)
|
||||
{
|
||||
currentPosition--;
|
||||
currentColor = bmp.GetPixel(currentPosition,height);
|
||||
currentColor = bmp.GetPixel(currentPosition, height);
|
||||
}
|
||||
|
||||
//Its here to let the new window include a little bit of the right
|
||||
int CorrectedX = currentPosition - (newWindowSize.Width) + Convert.ToInt32((float)newWindowSize.Width/100f*10f);
|
||||
int CorrectedX = currentPosition - (newWindowSize.Width) + Convert.ToInt32((float)newWindowSize.Width / 100f * 10f);
|
||||
int CorrectedY = Convert.ToInt32((float)newWindowSize.Height / 100f * 35f);
|
||||
if (CorrectedX <= 0)
|
||||
return new Rectangle(0,0,newWindowSize.Width,newWindowSize.Height);
|
||||
return new Rectangle(0, 0, newWindowSize.Width, newWindowSize.Height);
|
||||
|
||||
return new Rectangle(CorrectedX,CorrectedY,newWindowSize.Width,newWindowSize.Height);
|
||||
return new Rectangle(CorrectedX, CorrectedY, newWindowSize.Width, newWindowSize.Height);
|
||||
}
|
||||
//This method has been created with the help of chatGPT
|
||||
public Tyre.Type GetTyreTypeFromColor(Color inputColor)
|
||||
@@ -144,23 +143,4 @@ namespace OCR_Decode
|
||||
return type;
|
||||
}
|
||||
}
|
||||
struct Tyre
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
Soft,
|
||||
Medium,
|
||||
Hard,
|
||||
Inter,
|
||||
Wet,
|
||||
Undefined
|
||||
}
|
||||
public Type Coumpound;
|
||||
public int NumberOfLaps;
|
||||
public Tyre(Type type, int laps)
|
||||
{
|
||||
Coumpound = type;
|
||||
NumberOfLaps = laps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-4
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -17,6 +18,8 @@ namespace OCR_Decode
|
||||
const string TEMPORARY_IMAGE_FOLDER = @"C:\Users\Moi\Pictures\SeleniumScreens\DataSetHighRes\";
|
||||
int pageNmbr = 82;
|
||||
Reader Reader;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
int LoadMS = 0;
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -24,17 +27,34 @@ namespace OCR_Decode
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
stopWatch.Start();
|
||||
Reader = new Reader(CONFIG_FILE,TEMPORARY_IMAGE_FOLDER);
|
||||
stopWatch.Stop();
|
||||
LoadMS = (int)stopWatch.ElapsedMilliseconds;
|
||||
|
||||
RefreshUi();
|
||||
}
|
||||
private void RefreshUi()
|
||||
private async void RefreshUi()
|
||||
{
|
||||
|
||||
tbxResult.Text = "";
|
||||
|
||||
stopWatch.Restart();
|
||||
pbxImage.Image = Reader.Draw(pageNmbr);
|
||||
stopWatch.Stop();
|
||||
|
||||
tbxResult.Text = Reader.Decode(pageNmbr);
|
||||
int DrawMS = (int)stopWatch.ElapsedMilliseconds;
|
||||
|
||||
stopWatch.Restart();
|
||||
tbxResult.Text = await Reader.Decode(pageNmbr);
|
||||
stopWatch.Stop();
|
||||
|
||||
int OcrMS = (int)stopWatch.ElapsedMilliseconds;
|
||||
MessageBox.Show(
|
||||
"Loading took : " + Reader.ConvertMsToTime(LoadMS) +
|
||||
" Image splitting took : " + Reader.ConvertMsToTime(DrawMS) + Environment.NewLine +
|
||||
" Reading the infos from the image took : " + Reader.ConvertMsToTime(OcrMS) + Environment.NewLine
|
||||
);
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void btnNext_Click(object sender, EventArgs e)
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DriverData.cs" />
|
||||
<Compile Include="DriverDrsWindow.cs" />
|
||||
<Compile Include="DriverGapToLeaderWindow.cs" />
|
||||
<Compile Include="DriverLapTimeWindow.cs" />
|
||||
|
||||
+27
-70
@@ -7,6 +7,7 @@ using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OCR_Decode
|
||||
{
|
||||
@@ -115,25 +116,26 @@ namespace OCR_Decode
|
||||
Point driverSector3Position = new Point(driverSector3.GetProperty("x").GetInt32(), driverSector3.GetProperty("y").GetInt32());
|
||||
|
||||
float offset = (((float)MainZone.ZoneImage.Height - (float)(Drivers.Count * FirstZoneSize.Height)) / (float)Drivers.Count);
|
||||
Bitmap MainZoneImage = MainZone.ZoneImage;
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_DRIVERS; i++)
|
||||
{
|
||||
Point tmpPos = new Point(0, FirstZonePosition.Y + i * FirstZoneSize.Height - Convert.ToInt32(i * offset) /*- (i* (FirstZoneSize.Height / 32))*/);
|
||||
Zone newDriverZone = new Zone(MainZone.ZoneImage, new Rectangle(tmpPos, FirstZoneSize));
|
||||
Zone newDriverZone = new Zone(MainZoneImage, new Rectangle(tmpPos, FirstZoneSize));
|
||||
Bitmap zoneImg = newDriverZone.ZoneImage;
|
||||
|
||||
newDriverZone.AddWindow(new DriverPositionWindow(newDriverZone.ZoneImage, new Rectangle(driverPositionPosition, driverPositionArea)));
|
||||
newDriverZone.AddWindow(new DriverGapToLeaderWindow(newDriverZone.ZoneImage, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea)));
|
||||
newDriverZone.AddWindow(new DriverLapTimeWindow(newDriverZone.ZoneImage, new Rectangle(driverLapTimePosition, driverLapTimeArea)));
|
||||
newDriverZone.AddWindow(new DriverDrsWindow(newDriverZone.ZoneImage, new Rectangle(driverDrsPosition, driverDrsArea)));
|
||||
newDriverZone.AddWindow(new DriverTyresWindow(newDriverZone.ZoneImage, new Rectangle(driverTyresPosition, driverTyresArea)));
|
||||
newDriverZone.AddWindow(new DriverNameWindow(newDriverZone.ZoneImage, new Rectangle(driverNamePosition, driverNameArea)));
|
||||
newDriverZone.AddWindow(new DriverSector1Window(newDriverZone.ZoneImage, new Rectangle(driverSector1Position, driverSector1Area)));
|
||||
newDriverZone.AddWindow(new DriverSector2Window(newDriverZone.ZoneImage, new Rectangle(driverSector2Position, driverSector2Area)));
|
||||
newDriverZone.AddWindow(new DriverSector3Window(newDriverZone.ZoneImage, new Rectangle(driverSector3Position, driverSector3Area)));
|
||||
newDriverZone.AddWindow(new DriverPositionWindow(zoneImg, new Rectangle(driverPositionPosition, driverPositionArea)));
|
||||
newDriverZone.AddWindow(new DriverGapToLeaderWindow(zoneImg, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea)));
|
||||
newDriverZone.AddWindow(new DriverLapTimeWindow(zoneImg, new Rectangle(driverLapTimePosition, driverLapTimeArea)));
|
||||
newDriverZone.AddWindow(new DriverDrsWindow(zoneImg, new Rectangle(driverDrsPosition, driverDrsArea)));
|
||||
newDriverZone.AddWindow(new DriverTyresWindow(zoneImg, new Rectangle(driverTyresPosition, driverTyresArea)));
|
||||
newDriverZone.AddWindow(new DriverNameWindow(zoneImg, new Rectangle(driverNamePosition, driverNameArea)));
|
||||
newDriverZone.AddWindow(new DriverSector1Window(zoneImg, new Rectangle(driverSector1Position, driverSector1Area)));
|
||||
newDriverZone.AddWindow(new DriverSector2Window(zoneImg, new Rectangle(driverSector2Position, driverSector2Area)));
|
||||
newDriverZone.AddWindow(new DriverSector3Window(zoneImg, new Rectangle(driverSector3Position, driverSector3Area)));
|
||||
|
||||
MainZone.AddZone(newDriverZone);
|
||||
}
|
||||
|
||||
//MessageBox.Show("We have a main zone with " + MainZone.Zones.Count() + " Driver zones with " + MainZone.Zones[4].Windows.Count() + " windows each and we have " + Drivers.Count + " drivers");
|
||||
MainZones.Add(MainZone);
|
||||
}
|
||||
@@ -168,14 +170,14 @@ namespace OCR_Decode
|
||||
}
|
||||
}
|
||||
}
|
||||
public string Decode(int idImage)
|
||||
public async Task<string> Decode(int idImage)
|
||||
{
|
||||
string result = "";
|
||||
ChangeImage(idImage);
|
||||
List<List<Object>> mainResults = new List<List<Object>>();
|
||||
List<DriverData> mainResults = new List<DriverData>();
|
||||
|
||||
//Decode
|
||||
for (int mainZoneId = 0; mainZoneId < MainZones.Count;mainZoneId ++)
|
||||
for (int mainZoneId = 0; mainZoneId < MainZones.Count; mainZoneId++)
|
||||
{
|
||||
switch (mainZoneId)
|
||||
{
|
||||
@@ -183,64 +185,19 @@ namespace OCR_Decode
|
||||
//Main Zone
|
||||
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
|
||||
//Next there will be the title and laps added
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Display
|
||||
foreach (List<Object> objects in mainResults)
|
||||
foreach (DriverData driver in mainResults)
|
||||
{
|
||||
for (int objId = 0; objId < objects.Count; objId++)
|
||||
{
|
||||
switch (objId)
|
||||
{
|
||||
case 0:
|
||||
//Position
|
||||
result += "Position : " + (int)objects[objId] + " ";
|
||||
break;
|
||||
case 1:
|
||||
//Gap
|
||||
result += "Gap to leader : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||
break;
|
||||
case 2:
|
||||
//LapTime
|
||||
result += "Lap time : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||
break;
|
||||
case 3:
|
||||
//DRS
|
||||
result += "DRS : " + (bool)objects[objId] + "";
|
||||
break;
|
||||
case 4:
|
||||
//Tyres
|
||||
Tyre tyre = (Tyre)objects[objId];
|
||||
result += "Uses " + tyre.Coumpound + " tyre for " + tyre.NumberOfLaps + " laps";
|
||||
break;
|
||||
case 5:
|
||||
//Name
|
||||
result += "Driver name : " + (string)objects[objId] + " ";
|
||||
break;
|
||||
case 6:
|
||||
//Sector 1
|
||||
result += "Sector 1 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||
break;
|
||||
case 7:
|
||||
//Sector 1
|
||||
result += "Sector 2 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||
break;
|
||||
case 8:
|
||||
//Sector 1
|
||||
result += "Sector 3 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||
break;
|
||||
default:
|
||||
result += "Unknown source : " + objects[objId].ToString();
|
||||
break;
|
||||
}
|
||||
result += Environment.NewLine;
|
||||
}
|
||||
result += driver.ToString();
|
||||
result += Environment.NewLine;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -249,7 +206,7 @@ namespace OCR_Decode
|
||||
{
|
||||
//Convert.ToInt32 would round upand I dont want that
|
||||
int minuts = (int)((float)amountOfMs / (1000f * 60f));
|
||||
int seconds = (int)((amountOfMs - (minuts*60f*1000f))/1000);
|
||||
int seconds = (int)((amountOfMs - (minuts * 60f * 1000f)) / 1000);
|
||||
int ms = amountOfMs - ((minuts * 60 * 1000) + (seconds * 1000));
|
||||
|
||||
return minuts + ":" + seconds.ToString("00") + ":" + ms.ToString("000");
|
||||
@@ -274,11 +231,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)
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace OCR_Decode
|
||||
private Rectangle _bounds;
|
||||
private Bitmap _image;
|
||||
private string _name;
|
||||
protected static TesseractEngine Engine;
|
||||
protected TesseractEngine Engine;
|
||||
public Rectangle Bounds { get => _bounds; private set => _bounds = value; }
|
||||
public Bitmap Image { get => _image; set => _image = value; }
|
||||
public string Name { get => _name; protected set => _name = value; }
|
||||
@@ -37,15 +37,14 @@ namespace OCR_Decode
|
||||
{
|
||||
Image = image;
|
||||
Bounds = bounds;
|
||||
|
||||
Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||
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";
|
||||
}
|
||||
@@ -57,7 +56,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, TesseractEngine Engine)
|
||||
{
|
||||
string rawResult = "";
|
||||
int result = 0;
|
||||
@@ -104,7 +103,7 @@ namespace OCR_Decode
|
||||
} while (iter.Next(PageIteratorLevel.Word));
|
||||
}
|
||||
|
||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
|
||||
//enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + Regex.Replace(rawResult, "[^0-9A-Za-z]", "") + ".png");
|
||||
|
||||
List<string> rawNumbers;
|
||||
|
||||
@@ -153,7 +152,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, TesseractEngine Engine, string allowedChars = "",OcrImage.WindowType windowType = OcrImage.WindowType.Text)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
@@ -171,6 +170,7 @@ namespace OCR_Decode
|
||||
result += iter.GetText(PageIteratorLevel.Word);
|
||||
} while (iter.Next(PageIteratorLevel.Word));
|
||||
}
|
||||
/*
|
||||
if (allowedChars.Contains("S"))
|
||||
{
|
||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + result +".png");
|
||||
@@ -179,8 +179,7 @@ namespace OCR_Decode
|
||||
{
|
||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + result +".png");
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
page.Dispose();
|
||||
return result;
|
||||
}
|
||||
|
||||
+21
-11
@@ -62,20 +62,30 @@ namespace OCR_Decode
|
||||
{
|
||||
Windows.Add(window);
|
||||
}
|
||||
public virtual List<Object> Decode(List<string> drivers)
|
||||
public virtual async Task<DriverData> Decode(List<string> drivers)
|
||||
{
|
||||
List<Object> result = new List<Object>();
|
||||
foreach (Window w in Windows)
|
||||
DriverData result = new DriverData();
|
||||
Parallel.ForEach(Windows,async w =>
|
||||
{
|
||||
if (w is DriverNameWindow)
|
||||
{
|
||||
result.Add((w as DriverNameWindow).DecodePng(drivers));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(w.DecodePng());
|
||||
}
|
||||
}
|
||||
result.Name = (string)await (w as DriverNameWindow).DecodePng(drivers);
|
||||
if (w is DriverDrsWindow)
|
||||
result.DRS = (bool)await (w as DriverDrsWindow).DecodePng();
|
||||
if (w is DriverGapToLeaderWindow)
|
||||
result.GapToLeader = (int)await (w as DriverGapToLeaderWindow).DecodePng();
|
||||
if (w is DriverLapTimeWindow)
|
||||
result.LapTime = (int)await (w as DriverLapTimeWindow).DecodePng();
|
||||
if (w is DriverPositionWindow)
|
||||
result.Position = (int)await (w as DriverPositionWindow).DecodePng();
|
||||
if (w is DriverSector1Window)
|
||||
result.Sector1 = (int)await (w as DriverSector1Window).DecodePng();
|
||||
if (w is DriverSector2Window)
|
||||
result.Sector2 = (int)await (w as DriverSector2Window).DecodePng();
|
||||
if (w is DriverSector3Window)
|
||||
result.Sector3 = (int)await (w as DriverSector3Window).DecodePng();
|
||||
if (w is DriverTyresWindow)
|
||||
result.CurrentTyre = (Tyre)await (w as DriverTyresWindow).DecodePng();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user