Added the framework for the recognition and partial implement of name recognition

This commit is contained in:
2023-04-04 13:45:10 +02:00
parent f3bb302ac9
commit beec16f9d6
13 changed files with 79 additions and 26 deletions
+5
View File
@@ -13,5 +13,10 @@ namespace OCR_Decode
{
Name = "DRS";
}
public override object DecodePng()
{
//TODO
return false;
}
}
}
+4
View File
@@ -13,5 +13,9 @@ namespace OCR_Decode
{
Name = "Gap to leader";
}
public override object DecodePng()
{
return 0;
}
}
}
+4
View File
@@ -13,5 +13,9 @@ namespace OCR_Decode
{
Name = "Lap time";
}
public override object DecodePng()
{
return 0;
}
}
}
+5 -2
View File
@@ -10,6 +10,7 @@ namespace OCR_Decode
{
internal class DriverNameWindow : Window
{
public static Random rnd = new Random();
public DriverNameWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
{
Name = "Name";
@@ -18,7 +19,8 @@ namespace OCR_Decode
{
string result = "";
Image rawData = WindowImage;
Image rawData = Image;
rawData.Save(Reader.DEBUG_DUMP_FOLDER + Name + "_Before" + ".png");
TesseractEngine engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
@@ -35,7 +37,8 @@ namespace OCR_Decode
result += iter.GetText(PageIteratorLevel.Word);
} while (iter.Next(PageIteratorLevel.Word));
}
//REMOVE !!!
//result += rnd.Next(0,100);
return result;
}
}
+4
View File
@@ -13,5 +13,9 @@ namespace OCR_Decode
{
Name = "Position";
}
public override object DecodePng()
{
return 0;
}
}
}
+4
View File
@@ -13,5 +13,9 @@ namespace OCR_Decode
{
Name = "Sector 1";
}
public override object DecodePng()
{
return 0;
}
}
}
+4
View File
@@ -13,5 +13,9 @@ namespace OCR_Decode
{
Name = "Sector 2";
}
public override object DecodePng()
{
return 0;
}
}
}
+4
View File
@@ -13,5 +13,9 @@ namespace OCR_Decode
{
Name = "Sector 3";
}
public override object DecodePng()
{
return 0;
}
}
}
+13 -3
View File
@@ -13,6 +13,10 @@ namespace OCR_Decode
{
Name = "Tyres";
}
public override object DecodePng()
{
return new Tyre(Tyre.Type.Undefined, 0);
}
}
struct Tyre
{
@@ -22,9 +26,15 @@ namespace OCR_Decode
Medium,
Hard,
Inter,
Wet
Wet,
Undefined
}
public Type Coumpound;
public int NumberOfLaps;
public Tyre(Type type, int laps)
{
Coumpound = type;
NumberOfLaps = laps;
}
public int numberOfLaps;
public Type type;
}
}
+1
View File
@@ -50,6 +50,7 @@
this.tbxResult.Location = new System.Drawing.Point(441, 618);
this.tbxResult.Multiline = true;
this.tbxResult.Name = "tbxResult";
this.tbxResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.tbxResult.Size = new System.Drawing.Size(571, 192);
this.tbxResult.TabIndex = 1;
//
+2
View File
@@ -25,6 +25,8 @@ namespace OCR_Decode
{
Reader = new Reader(CONFIG_FILE,TEMPORARY_IMAGE_FOLDER);
pbxImage.Image = Reader.Draw(9);
tbxResult.Text = Reader.Decode(9);
}
}
}
+24 -17
View File
@@ -23,6 +23,7 @@ namespace OCR_Decode
public List<Zone> MainZones { get => _mainZones; set => _mainZones = value; }
const string DEFAULT_IMAGE_NAME = "screen_";
public const string DEBUG_DUMP_FOLDER = @"C:\Users\Moi\Desktop\imgDump\Decode\";
const int NUMBER_OF_DRIVERS = 20;
public Reader(string configFile, string imageFolder)
@@ -174,55 +175,63 @@ namespace OCR_Decode
List<List<Object>> mainResults = new List<List<Object>>();
//Decode
foreach (Zone z in MainZones)
for (int mainZoneId = 0; mainZoneId < MainZones.Count;mainZoneId ++)
{
foreach (Zone zz in z.Zones)
switch (mainZoneId)
{
mainResults.Add(zz.Decode());
case 0:
//Main Zone
foreach (Zone z in MainZones[mainZoneId].Zones)
{
mainResults.Add(z.Decode());
}
break;
//Next there will be the title and laps added
}
}
//Display
foreach (List<Object> objects in mainResults)
{
for (int objId = 1; objId <= objects.Count; objId++)
for (int objId = 0; objId < objects.Count; objId++)
{
switch (objId)
{
case 1:
case 0:
//Position
result += "Position : " + (int)objects[objId] + " ";
break;
case 2:
case 1:
//Gap
result += "Gap to leader : " + ConvertMsToTime((int)objects[objId]) + " ";
break;
case 3:
case 2:
//LapTime
result += "Lap time : " + ConvertMsToTime((int)objects[objId]) + " ";
break;
case 4:
case 3:
//DRS
result += "DRS : " + (bool)objects[objId] + "";
break;
case 5:
case 4:
//Tyres
Tyre tyre = (Tyre)objects[objId];
result += "Tyre : " + tyre.type + " laps with the tyre : " + tyre.numberOfLaps + " ";
result += "Tyre : " + tyre.Coumpound + " laps with the tyre : " + tyre.NumberOfLaps + " ";
break;
case 6:
case 5:
//Name
result += "Driver name : " + (string)objects[objId] + " ";
break;
case 7:
case 6:
//Sector 1
result += "Sector 1 : " + ConvertMsToTime((int)objects[objId]) + " ";
break;
case 8:
case 7:
//Sector 1
result += "Sector 2 : " + ConvertMsToTime((int)objects[objId]) + " ";
break;
case 9:
case 8:
//Sector 1
result += "Sector 3 : " + ConvertMsToTime((int)objects[objId]) + " ";
break;
@@ -246,7 +255,6 @@ namespace OCR_Decode
}
public Bitmap Draw(int idImage)
{
string debugDumpFolder = @"C:\Users\Moi\Desktop\imgDump\Decode\";
Bitmap result;
try
{
@@ -265,7 +273,7 @@ namespace OCR_Decode
int count = 0;
foreach (Zone zz in z.Zones)
{
string driverFolder = debugDumpFolder + "driver" + count + "\\";
string driverFolder = DEBUG_DUMP_FOLDER + "driver" + count + "\\";
if (!Directory.Exists(driverFolder))
Directory.CreateDirectory(driverFolder);
@@ -274,7 +282,6 @@ namespace OCR_Decode
g.DrawRectangle(Pens.Red, z.Bounds);
foreach (Window w in zz.Windows)
{
w.WindowImage.Save(driverFolder + w.Name + ".png");
g.DrawRectangle(Pens.Blue, new Rectangle(z.Bounds.X + zz.Bounds.X, z.Bounds.Y + zz.Bounds.Y, zz.Bounds.Width, zz.Bounds.Height));
}
+5 -4
View File
@@ -32,7 +32,7 @@ namespace OCR_Decode
_image = Image;
foreach (Window w in Windows)
{
w.Image = Image;
w.Image = ZoneImage;
}
foreach (Zone z in Zones)
{
@@ -47,11 +47,12 @@ namespace OCR_Decode
public Zone(Bitmap image, Rectangle bounds)
{
Image = image;
Bounds = bounds;
Windows = new List<Window>();
Zones = new List<Zone>();
//You cant set the image in the CTOR because the processing is impossible at first initiation
_image = image;
Bounds = bounds;
}
public virtual void AddZone(Zone zone)
{