Added the framework for the recognition and partial implement of name recognition
This commit is contained in:
@@ -13,5 +13,10 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "DRS";
|
Name = "DRS";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Gap to leader";
|
Name = "Gap to leader";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Lap time";
|
Name = "Lap time";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
internal class DriverNameWindow : Window
|
internal class DriverNameWindow : Window
|
||||||
{
|
{
|
||||||
|
public static Random rnd = new Random();
|
||||||
public DriverNameWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
|
public DriverNameWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
|
||||||
{
|
{
|
||||||
Name = "Name";
|
Name = "Name";
|
||||||
@@ -18,7 +19,8 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
string result = "";
|
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);
|
TesseractEngine engine = new TesseractEngine(TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||||
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
|
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
|
||||||
@@ -35,7 +37,8 @@ namespace OCR_Decode
|
|||||||
result += iter.GetText(PageIteratorLevel.Word);
|
result += iter.GetText(PageIteratorLevel.Word);
|
||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
}
|
}
|
||||||
|
//REMOVE !!!
|
||||||
|
//result += rnd.Next(0,100);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Position";
|
Name = "Position";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Sector 1";
|
Name = "Sector 1";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Sector 2";
|
Name = "Sector 2";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Sector 3";
|
Name = "Sector 3";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Name = "Tyres";
|
Name = "Tyres";
|
||||||
}
|
}
|
||||||
|
public override object DecodePng()
|
||||||
|
{
|
||||||
|
return new Tyre(Tyre.Type.Undefined, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
struct Tyre
|
struct Tyre
|
||||||
{
|
{
|
||||||
@@ -22,9 +26,15 @@ namespace OCR_Decode
|
|||||||
Medium,
|
Medium,
|
||||||
Hard,
|
Hard,
|
||||||
Inter,
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+1
@@ -50,6 +50,7 @@
|
|||||||
this.tbxResult.Location = new System.Drawing.Point(441, 618);
|
this.tbxResult.Location = new System.Drawing.Point(441, 618);
|
||||||
this.tbxResult.Multiline = true;
|
this.tbxResult.Multiline = true;
|
||||||
this.tbxResult.Name = "tbxResult";
|
this.tbxResult.Name = "tbxResult";
|
||||||
|
this.tbxResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||||
this.tbxResult.Size = new System.Drawing.Size(571, 192);
|
this.tbxResult.Size = new System.Drawing.Size(571, 192);
|
||||||
this.tbxResult.TabIndex = 1;
|
this.tbxResult.TabIndex = 1;
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ namespace OCR_Decode
|
|||||||
{
|
{
|
||||||
Reader = new Reader(CONFIG_FILE,TEMPORARY_IMAGE_FOLDER);
|
Reader = new Reader(CONFIG_FILE,TEMPORARY_IMAGE_FOLDER);
|
||||||
pbxImage.Image = Reader.Draw(9);
|
pbxImage.Image = Reader.Draw(9);
|
||||||
|
|
||||||
|
tbxResult.Text = Reader.Decode(9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-17
@@ -23,6 +23,7 @@ namespace OCR_Decode
|
|||||||
public List<Zone> MainZones { get => _mainZones; set => _mainZones = value; }
|
public List<Zone> MainZones { get => _mainZones; set => _mainZones = value; }
|
||||||
|
|
||||||
const string DEFAULT_IMAGE_NAME = "screen_";
|
const string DEFAULT_IMAGE_NAME = "screen_";
|
||||||
|
public const string DEBUG_DUMP_FOLDER = @"C:\Users\Moi\Desktop\imgDump\Decode\";
|
||||||
const int NUMBER_OF_DRIVERS = 20;
|
const int NUMBER_OF_DRIVERS = 20;
|
||||||
|
|
||||||
public Reader(string configFile, string imageFolder)
|
public Reader(string configFile, string imageFolder)
|
||||||
@@ -174,55 +175,63 @@ namespace OCR_Decode
|
|||||||
List<List<Object>> mainResults = new List<List<Object>>();
|
List<List<Object>> mainResults = new List<List<Object>>();
|
||||||
|
|
||||||
//Decode
|
//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
|
//Display
|
||||||
foreach (List<Object> objects in mainResults)
|
foreach (List<Object> objects in mainResults)
|
||||||
{
|
{
|
||||||
for (int objId = 1; objId <= objects.Count; objId++)
|
for (int objId = 0; objId < objects.Count; objId++)
|
||||||
{
|
{
|
||||||
switch (objId)
|
switch (objId)
|
||||||
{
|
{
|
||||||
case 1:
|
case 0:
|
||||||
//Position
|
//Position
|
||||||
result += "Position : " + (int)objects[objId] + " ";
|
result += "Position : " + (int)objects[objId] + " ";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 1:
|
||||||
//Gap
|
//Gap
|
||||||
result += "Gap to leader : " + ConvertMsToTime((int)objects[objId]) + " ";
|
result += "Gap to leader : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 2:
|
||||||
//LapTime
|
//LapTime
|
||||||
result += "Lap time : " + ConvertMsToTime((int)objects[objId]) + " ";
|
result += "Lap time : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 3:
|
||||||
//DRS
|
//DRS
|
||||||
result += "DRS : " + (bool)objects[objId] + "";
|
result += "DRS : " + (bool)objects[objId] + "";
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 4:
|
||||||
//Tyres
|
//Tyres
|
||||||
Tyre tyre = (Tyre)objects[objId];
|
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;
|
break;
|
||||||
case 6:
|
case 5:
|
||||||
//Name
|
//Name
|
||||||
result += "Driver name : " + (string)objects[objId] + " ";
|
result += "Driver name : " + (string)objects[objId] + " ";
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 6:
|
||||||
//Sector 1
|
//Sector 1
|
||||||
result += "Sector 1 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
result += "Sector 1 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 7:
|
||||||
//Sector 1
|
//Sector 1
|
||||||
result += "Sector 2 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
result += "Sector 2 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 8:
|
||||||
//Sector 1
|
//Sector 1
|
||||||
result += "Sector 3 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
result += "Sector 3 : " + ConvertMsToTime((int)objects[objId]) + " ";
|
||||||
break;
|
break;
|
||||||
@@ -246,7 +255,6 @@ namespace OCR_Decode
|
|||||||
}
|
}
|
||||||
public Bitmap Draw(int idImage)
|
public Bitmap Draw(int idImage)
|
||||||
{
|
{
|
||||||
string debugDumpFolder = @"C:\Users\Moi\Desktop\imgDump\Decode\";
|
|
||||||
Bitmap result;
|
Bitmap result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -265,7 +273,7 @@ namespace OCR_Decode
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (Zone zz in z.Zones)
|
foreach (Zone zz in z.Zones)
|
||||||
{
|
{
|
||||||
string driverFolder = debugDumpFolder + "driver" + count + "\\";
|
string driverFolder = DEBUG_DUMP_FOLDER + "driver" + count + "\\";
|
||||||
if (!Directory.Exists(driverFolder))
|
if (!Directory.Exists(driverFolder))
|
||||||
Directory.CreateDirectory(driverFolder);
|
Directory.CreateDirectory(driverFolder);
|
||||||
|
|
||||||
@@ -274,7 +282,6 @@ namespace OCR_Decode
|
|||||||
g.DrawRectangle(Pens.Red, z.Bounds);
|
g.DrawRectangle(Pens.Red, z.Bounds);
|
||||||
foreach (Window w in zz.Windows)
|
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));
|
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
@@ -32,7 +32,7 @@ namespace OCR_Decode
|
|||||||
_image = Image;
|
_image = Image;
|
||||||
foreach (Window w in Windows)
|
foreach (Window w in Windows)
|
||||||
{
|
{
|
||||||
w.Image = Image;
|
w.Image = ZoneImage;
|
||||||
}
|
}
|
||||||
foreach (Zone z in Zones)
|
foreach (Zone z in Zones)
|
||||||
{
|
{
|
||||||
@@ -47,11 +47,12 @@ namespace OCR_Decode
|
|||||||
|
|
||||||
public Zone(Bitmap image, Rectangle bounds)
|
public Zone(Bitmap image, Rectangle bounds)
|
||||||
{
|
{
|
||||||
Image = image;
|
|
||||||
Bounds = bounds;
|
|
||||||
|
|
||||||
Windows = new List<Window>();
|
Windows = new List<Window>();
|
||||||
Zones = new List<Zone>();
|
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)
|
public virtual void AddZone(Zone zone)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user