Increased OCR performances
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ namespace OCR_Decode
|
|||||||
if (greenValue > EmptyDrsGreenValue + EmptyDrsGreenValue / 100 * 30)
|
if (greenValue > EmptyDrsGreenValue + EmptyDrsGreenValue / 100 * 30)
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "DRS" + result + ".png");
|
//WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "DRS" + result + ".png");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -68,28 +68,31 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public Rectangle GetBox()
|
public Rectangle GetBox()
|
||||||
{
|
{
|
||||||
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
|
|
||||||
Engine.SetVariable("tessedit_char_whitelist", "");
|
|
||||||
Page page = Engine.Process(tessImage);
|
|
||||||
|
|
||||||
using (var iter = page.GetIterator())
|
|
||||||
{
|
{
|
||||||
iter.Begin();
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
do
|
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
|
||||||
|
Engine.SetVariable("tessedit_char_whitelist", "");
|
||||||
|
Page page = Engine.Process(tessImage);
|
||||||
|
|
||||||
|
using (var iter = page.GetIterator())
|
||||||
{
|
{
|
||||||
Rect boundingBox;
|
iter.Begin();
|
||||||
|
do
|
||||||
// Get the bounding box for the current element
|
|
||||||
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
|
|
||||||
{
|
{
|
||||||
page.Dispose();
|
Rect boundingBox;
|
||||||
return new Rectangle(boundingBox.X1, boundingBox.X2, boundingBox.Width, boundingBox.Height);
|
|
||||||
}
|
|
||||||
} while (iter.Next(PageIteratorLevel.Word));
|
|
||||||
|
|
||||||
page.Dispose();
|
// Get the bounding box for the current element
|
||||||
return new Rectangle(0, 0, 0, 0);
|
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
|
||||||
|
{
|
||||||
|
page.Dispose();
|
||||||
|
return new Rectangle(boundingBox.X1, boundingBox.X2, boundingBox.Width, boundingBox.Height);
|
||||||
|
}
|
||||||
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
|
|
||||||
|
page.Dispose();
|
||||||
|
return new Rectangle(0, 0, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Tesseract;
|
||||||
|
|
||||||
namespace OCR_Decode
|
namespace OCR_Decode
|
||||||
{
|
{
|
||||||
@@ -15,8 +16,12 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Gap);
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
return result;
|
{
|
||||||
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
|
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Gap,Engine);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,12 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage,OcrImage.WindowType.LapTime);
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
return result;
|
{
|
||||||
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
|
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.LapTime,Engine);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,19 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override async Task<object> DecodePng(List<string> DriverList)
|
public override async Task<object> DecodePng(List<string> DriverList)
|
||||||
{
|
{
|
||||||
string result = "";
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
result = await GetStringFromPng(WindowImage);
|
|
||||||
|
|
||||||
if (!IsADriver(DriverList, result))
|
|
||||||
{
|
{
|
||||||
//I put everything in uppercase to try to lower the chances of bad answers
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
result = FindClosestMatch(DriverList.ConvertAll(d => d.ToUpper()), result.ToUpper());
|
string result = "";
|
||||||
|
result = await GetStringFromPng(WindowImage,Engine);
|
||||||
|
|
||||||
|
if (!IsADriver(DriverList, result))
|
||||||
|
{
|
||||||
|
//I put everything in uppercase to try to lower the chances of bad answers
|
||||||
|
result = FindClosestMatch(DriverList.ConvertAll(d => d.ToUpper()), result.ToUpper());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
private static bool IsADriver(List<string> drivers, string potentialDriver)
|
private static bool IsADriver(List<string> drivers, string potentialDriver)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Tesseract;
|
||||||
|
|
||||||
namespace OCR_Decode
|
namespace OCR_Decode
|
||||||
{
|
{
|
||||||
@@ -15,19 +16,23 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
string result = await GetStringFromPng(WindowImage,"0123456789");
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
|
|
||||||
int position;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
position = Convert.ToInt32(result);
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
|
string result = await GetStringFromPng(WindowImage,Engine, "0123456789");
|
||||||
|
|
||||||
|
int position;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
position = Convert.ToInt32(result);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
position = -1;
|
||||||
|
//WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "FailedPosition" + ".png");
|
||||||
|
}
|
||||||
|
return position;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
position = -1;
|
|
||||||
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "FailedPosition"+".png");
|
|
||||||
}
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Tesseract;
|
||||||
|
|
||||||
namespace OCR_Decode
|
namespace OCR_Decode
|
||||||
{
|
{
|
||||||
@@ -15,8 +16,12 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
return result;
|
{
|
||||||
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
|
int result = await GetTimeFromPng(WindowImage,OcrImage.WindowType.Sector,Engine);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Tesseract;
|
||||||
|
|
||||||
namespace OCR_Decode
|
namespace OCR_Decode
|
||||||
{
|
{
|
||||||
@@ -15,8 +16,12 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector);
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
return result;
|
{
|
||||||
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
|
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector,Engine);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Tesseract;
|
||||||
|
|
||||||
namespace OCR_Decode
|
namespace OCR_Decode
|
||||||
{
|
{
|
||||||
@@ -15,8 +16,12 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public override async Task<object> DecodePng()
|
public override async Task<object> DecodePng()
|
||||||
{
|
{
|
||||||
int result = await GetTimeFromPng(WindowImage,OcrImage.WindowType.Sector);
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
return result;
|
{
|
||||||
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
|
int result = await GetTimeFromPng(WindowImage, OcrImage.WindowType.Sector,Engine);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
private static Random rnd = new Random();
|
private static Random rnd = new Random();
|
||||||
|
|
||||||
public static Color SOFT_TYRE_COLOR = Color.FromArgb(0xff,0x00,0x00);
|
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 MEDIUM_TYRE_COLOR = Color.FromArgb(0xf5, 0xbf, 0x00);
|
||||||
public static Color HARD_TYRE_COLOR = Color.FromArgb(0xd9,0xd8,0xd4);
|
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 INTER_TYRE_COLOR = Color.FromArgb(0x00, 0xa4, 0x2e);
|
||||||
public static Color WET_TYRE_COLOR = Color.FromArgb(0x27,0x60,0xa6);
|
public static Color WET_TYRE_COLOR = Color.FromArgb(0x27, 0x60, 0xa6);
|
||||||
|
|
||||||
public DriverTyresWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
|
public DriverTyresWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
|
||||||
{
|
{
|
||||||
@@ -31,79 +31,82 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Bitmap tyreZone = GetSmallBitmapFromBigOne(WindowImage, FindTyreZone());
|
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;
|
Tyre.Type type = Tyre.Type.Undefined;
|
||||||
int laps = -1;
|
int laps = -1;
|
||||||
|
using (var Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default))
|
||||||
//MHIWsmhiw so we can detect Soft Medium Hard Inters and Wet tyres
|
|
||||||
string text = await GetStringFromPng(tyreZone, "SMHIW", OcrImage.WindowType.Tyre);
|
|
||||||
if (text.Length == 1 && text != "")
|
|
||||||
{
|
{
|
||||||
//We found a tire letter
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
laps = 0;
|
//MHIWsmhiw so we can detect Soft Medium Hard Inters and Wet tyres
|
||||||
text = text.ToUpper();
|
string text = await GetStringFromPng(tyreZone, Engine, "SMHIW", OcrImage.WindowType.Tyre);
|
||||||
switch (text[0])
|
if (text.Length == 1 && text != "")
|
||||||
{
|
{
|
||||||
case 'S':
|
//We found a tire letter
|
||||||
type = Tyre.Type.Soft;
|
laps = 0;
|
||||||
break;
|
text = text.ToUpper();
|
||||||
case 'M':
|
switch (text[0])
|
||||||
type = Tyre.Type.Medium;
|
{
|
||||||
break;
|
case 'S':
|
||||||
case 'H':
|
type = Tyre.Type.Soft;
|
||||||
type = Tyre.Type.Hard;
|
break;
|
||||||
break;
|
case 'M':
|
||||||
case 'I':
|
type = Tyre.Type.Medium;
|
||||||
type = Tyre.Type.Inter;
|
break;
|
||||||
break;
|
case 'H':
|
||||||
case 'W':
|
type = Tyre.Type.Hard;
|
||||||
type = Tyre.Type.Wet;
|
break;
|
||||||
break;
|
case 'I':
|
||||||
default:
|
type = Tyre.Type.Inter;
|
||||||
type = Tyre.Type.Undefined;
|
break;
|
||||||
break;
|
case 'W':
|
||||||
|
type = Tyre.Type.Wet;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
type = Tyre.Type.Undefined;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
|
||||||
{
|
|
||||||
string number = await GetStringFromPng(tyreZone, "0123456789", OcrImage.WindowType.Tyre);
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
laps = Convert.ToInt32(number);
|
string number = await GetStringFromPng(tyreZone, Engine, "0123456789", OcrImage.WindowType.Tyre);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
laps = Convert.ToInt32(number);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
laps = -1;
|
||||||
|
}
|
||||||
|
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone)));
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
laps = -1;
|
|
||||||
}
|
|
||||||
type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone)));
|
|
||||||
}
|
|
||||||
|
|
||||||
tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
//tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png");
|
||||||
return new Tyre(type,laps);
|
return new Tyre(type, laps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private Rectangle FindTyreZone()
|
private Rectangle FindTyreZone()
|
||||||
{
|
{
|
||||||
Bitmap bmp = WindowImage;
|
Bitmap bmp = WindowImage;
|
||||||
int currentPosition = bmp.Width;
|
int currentPosition = bmp.Width;
|
||||||
int height = bmp.Height / 2;
|
int height = bmp.Height / 2;
|
||||||
Color limitColor = Color.FromArgb(0x50,0x50,0x50);
|
Color limitColor = Color.FromArgb(0x50, 0x50, 0x50);
|
||||||
Color currentColor = Color.FromArgb(0,0,0);
|
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--;
|
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
|
//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);
|
int CorrectedY = Convert.ToInt32((float)newWindowSize.Height / 100f * 35f);
|
||||||
if (CorrectedX <= 0)
|
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
|
//This method has been created with the help of chatGPT
|
||||||
public Tyre.Type GetTyreTypeFromColor(Color inputColor)
|
public Tyre.Type GetTyreTypeFromColor(Color inputColor)
|
||||||
@@ -143,23 +146,4 @@ namespace OCR_Decode
|
|||||||
return type;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="DriverData.cs" />
|
||||||
<Compile Include="DriverDrsWindow.cs" />
|
<Compile Include="DriverDrsWindow.cs" />
|
||||||
<Compile Include="DriverGapToLeaderWindow.cs" />
|
<Compile Include="DriverGapToLeaderWindow.cs" />
|
||||||
<Compile Include="DriverLapTimeWindow.cs" />
|
<Compile Include="DriverLapTimeWindow.cs" />
|
||||||
|
|||||||
+10
-56
@@ -174,76 +174,30 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
ChangeImage(idImage);
|
ChangeImage(idImage);
|
||||||
List<List<Object>> mainResults = new List<List<Object>>();
|
List<DriverData> mainResults = new List<DriverData>();
|
||||||
|
|
||||||
//Decode
|
//Decode
|
||||||
for (int mainZoneId = 0; mainZoneId < MainZones.Count;mainZoneId ++)
|
for (int mainZoneId = 0; mainZoneId < MainZones.Count; mainZoneId++)
|
||||||
{
|
{
|
||||||
switch (mainZoneId)
|
switch (mainZoneId)
|
||||||
{
|
{
|
||||||
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(await 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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Display
|
//Display
|
||||||
foreach (List<Object> objects in mainResults)
|
foreach (DriverData driver in mainResults)
|
||||||
{
|
{
|
||||||
for (int objId = 0; objId < objects.Count; objId++)
|
result += driver.ToString();
|
||||||
{
|
result += Environment.NewLine;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -252,7 +206,7 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
//Convert.ToInt32 would round upand I dont want that
|
//Convert.ToInt32 would round upand I dont want that
|
||||||
int minuts = (int)((float)amountOfMs / (1000f * 60f));
|
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));
|
int ms = amountOfMs - ((minuts * 60 * 1000) + (seconds * 1000));
|
||||||
|
|
||||||
return minuts + ":" + seconds.ToString("00") + ":" + ms.ToString("000");
|
return minuts + ":" + seconds.ToString("00") + ":" + ms.ToString("000");
|
||||||
@@ -279,7 +233,7 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
//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");
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace OCR_Decode
|
|||||||
private Rectangle _bounds;
|
private Rectangle _bounds;
|
||||||
private Bitmap _image;
|
private Bitmap _image;
|
||||||
private string _name;
|
private string _name;
|
||||||
protected static TesseractEngine Engine = null;
|
//protected static TesseractEngine Engine = null;
|
||||||
public Rectangle Bounds { get => _bounds; private set => _bounds = value; }
|
public Rectangle Bounds { get => _bounds; private set => _bounds = value; }
|
||||||
public Bitmap Image { get => _image; set => _image = value; }
|
public Bitmap Image { get => _image; set => _image = value; }
|
||||||
public string Name { get => _name; protected set => _name = value; }
|
public string Name { get => _name; protected set => _name = value; }
|
||||||
@@ -37,12 +37,13 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Image = image;
|
Image = image;
|
||||||
Bounds = bounds;
|
Bounds = bounds;
|
||||||
|
/*
|
||||||
if (Engine == null)
|
if (Engine == null)
|
||||||
{
|
{
|
||||||
Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
Engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||||
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
Engine.DefaultPageSegMode = PageSegMode.SingleLine;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
public virtual async Task<Object> DecodePng()
|
public virtual async Task<Object> DecodePng()
|
||||||
{
|
{
|
||||||
@@ -60,7 +61,7 @@ namespace OCR_Decode
|
|||||||
return stream.ToArray();
|
return stream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static async Task<int> GetTimeFromPng(Bitmap wImage,OcrImage.WindowType type)
|
public static async Task<int> GetTimeFromPng(Bitmap wImage,OcrImage.WindowType type, TesseractEngine Engine)
|
||||||
{
|
{
|
||||||
string rawResult = "";
|
string rawResult = "";
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@@ -107,7 +108,7 @@ namespace OCR_Decode
|
|||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} 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;
|
List<string> rawNumbers;
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ namespace OCR_Decode
|
|||||||
page.Dispose();
|
page.Dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public static async Task<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 = "";
|
string result = "";
|
||||||
|
|
||||||
@@ -174,6 +175,7 @@ namespace OCR_Decode
|
|||||||
result += iter.GetText(PageIteratorLevel.Word);
|
result += iter.GetText(PageIteratorLevel.Word);
|
||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (allowedChars.Contains("S"))
|
if (allowedChars.Contains("S"))
|
||||||
{
|
{
|
||||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + result +".png");
|
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + result +".png");
|
||||||
@@ -182,8 +184,7 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + result +".png");
|
enhancedImage.Save(Reader.DEBUG_DUMP_FOLDER + result +".png");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
page.Dispose();
|
page.Dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-11
@@ -62,20 +62,30 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Windows.Add(window);
|
Windows.Add(window);
|
||||||
}
|
}
|
||||||
public virtual async Task<List<Object>> Decode(List<string> drivers)
|
public virtual async Task<DriverData> Decode(List<string> drivers)
|
||||||
{
|
{
|
||||||
List<Object> result = new List<Object>();
|
DriverData result = new DriverData();
|
||||||
foreach (Window w in Windows)
|
Parallel.ForEach(Windows,async w =>
|
||||||
{
|
{
|
||||||
if (w is DriverNameWindow)
|
if (w is DriverNameWindow)
|
||||||
{
|
result.Name = (string)await (w as DriverNameWindow).DecodePng(drivers);
|
||||||
result.Add(await (w as DriverNameWindow).DecodePng(drivers));
|
if (w is DriverDrsWindow)
|
||||||
}
|
result.DRS = (bool)await (w as DriverDrsWindow).DecodePng();
|
||||||
else
|
if (w is DriverGapToLeaderWindow)
|
||||||
{
|
result.GapToLeader = (int)await (w as DriverGapToLeaderWindow).DecodePng();
|
||||||
result.Add(await w.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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user