Fixed the slowest drivers windows and cleaned some of the code
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/// Author : Maxime Rohmer
|
||||
/// Date : 08/05/2023
|
||||
/// Date : 30/05/2023
|
||||
/// File : ConfigurationTool.cs
|
||||
/// Brief : Class that contains all the methods needed to create a config file for the OCR
|
||||
/// Version : 0.1
|
||||
/// Brief : Class that contains all the methods used to create config files for the main programm
|
||||
/// Version : Alpha 1.0
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -23,7 +23,11 @@ namespace Test_Merge
|
||||
public const int NUMBER_OF_DRIVERS = 20;
|
||||
public const int NUMBER_OF_ZONES = 9;
|
||||
public const string CONFIGS_FOLDER_NAME = "./Presets/";
|
||||
|
||||
/// <summary>
|
||||
/// Creates the configuration tool. It can only be created if you already have the dimensions of the main zone
|
||||
/// </summary>
|
||||
/// <param name="fullImage">The full image coming from the F1TV Data Channel</param>
|
||||
/// <param name="mainZoneDimensions">The dimensions of the zone where all the drivers data are situated</param>
|
||||
public ConfigurationTool(Bitmap fullImage, Rectangle mainZoneDimensions)
|
||||
{
|
||||
MainZone = new Zone(fullImage, mainZoneDimensions,"Main");
|
||||
@@ -54,9 +58,9 @@ namespace Test_Merge
|
||||
|
||||
JsonObject jsonFileObject = new JsonObject();
|
||||
|
||||
//Creating the mainZone object
|
||||
|
||||
//Creates the mainZone object
|
||||
JsonObject mainZoneObject = new JsonObject();
|
||||
|
||||
mainZoneObject.Add("x",MainZone.Bounds.X);
|
||||
mainZoneObject.Add("y",MainZone.Bounds.Y);
|
||||
mainZoneObject.Add("width",MainZone.Bounds.Width);
|
||||
@@ -64,6 +68,7 @@ namespace Test_Merge
|
||||
|
||||
JsonArray driverZonesArray = new JsonArray();
|
||||
|
||||
//Creates all the subzones that contain driver infos
|
||||
int DriverID = 0;
|
||||
foreach (Zone driverZone in MainZone.Zones)
|
||||
{
|
||||
@@ -76,8 +81,10 @@ namespace Test_Merge
|
||||
driverZoneObject.Add("height", driverZone.Bounds.Height);
|
||||
|
||||
JsonArray windowsArray = new JsonArray();
|
||||
|
||||
JsonObject windowObject = new JsonObject();
|
||||
|
||||
//Creates all the windows of the current driver zone
|
||||
//Note : We store ALL the windows and zones in the JSON because they are not spaced exactly the same on the main zone
|
||||
foreach (Window window in driverZone.Windows)
|
||||
{
|
||||
windowObject.Add(window.Name, new JsonObject {
|
||||
@@ -149,35 +156,35 @@ namespace Test_Merge
|
||||
driverZone.AddWindow(new DriverPositionWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
break;
|
||||
case 2:
|
||||
//First zone should be the Gap to leader
|
||||
//Second zone should be the Gap to leader
|
||||
driverZone.AddWindow(new DriverGapToLeaderWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
break;
|
||||
case 3:
|
||||
//First zone should be the driver's Lap Time
|
||||
//Third zone should be the driver's Lap Time
|
||||
driverZone.AddWindow(new DriverLapTimeWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
break;
|
||||
case 4:
|
||||
//First zone should be the driver's DRS status
|
||||
//Fourth zone should be the driver's DRS status
|
||||
driverZone.AddWindow(new DriverDrsWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
break;
|
||||
case 5:
|
||||
//First zone should be the driver's Tyre's informations
|
||||
//Fifth zone should be the driver's Tyre's informations
|
||||
driverZone.AddWindow(new DriverTyresWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
break;
|
||||
case 6:
|
||||
//First zone should be the driver's Name
|
||||
//Sixth zone should be the driver's Name
|
||||
driverZone.AddWindow(new DriverNameWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
break;
|
||||
case 7:
|
||||
//First zone should be the driver's First Sector
|
||||
//Seventh zone should be the driver's First Sector
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 1, false));
|
||||
break;
|
||||
case 8:
|
||||
//First zone should be the driver's Second Sector
|
||||
//Zone number eight should be the driver's Second Sector
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 2, false));
|
||||
break;
|
||||
case 9:
|
||||
//First zone should be the driver's Position Sector
|
||||
//Zone number nine should be the driver's Position Sector
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 3, false));
|
||||
break;
|
||||
}
|
||||
@@ -186,6 +193,7 @@ namespace Test_Merge
|
||||
}
|
||||
/// <summary>
|
||||
/// This will automatically create all the driver zones at the correct places if the main zone has been weel positionned
|
||||
/// You cant just divide the image by the number of pilots or it will be messy and inconsistent at the end (Garbage in Garbage Out)
|
||||
/// </summary>
|
||||
public void AutoCalibrate()
|
||||
{
|
||||
@@ -197,6 +205,8 @@ namespace Test_Merge
|
||||
var tessImage = Pix.LoadFromMemory(Window.ImageToByte(image));
|
||||
|
||||
Page page = engine.Process(tessImage);
|
||||
//Runs a quick OCR detection. Not to detect any content but just to detect where is all the text positionned.
|
||||
//For each row it decides the best Zone location and adds it to the Driver zone list
|
||||
using (var iter = page.GetIterator())
|
||||
{
|
||||
iter.Begin();
|
||||
@@ -205,7 +215,6 @@ namespace Test_Merge
|
||||
Rect boundingBox;
|
||||
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
|
||||
{
|
||||
//var text = iter.GetText(PageIteratorLevel.Word).ToUpper();
|
||||
//We remove all the rectangles that are definitely too big
|
||||
if (boundingBox.Height < image.Height / NUMBER_OF_DRIVERS)
|
||||
{
|
||||
@@ -244,7 +253,6 @@ namespace Test_Merge
|
||||
//We add the driver zones
|
||||
Zone driverZone = new Zone(MainZone.ZoneImage, windowRectangle, "DriverZone");
|
||||
MainZone.AddZone(driverZone);
|
||||
|
||||
//driverZone.ZoneImage.Save("Driver" + i+".png");
|
||||
i++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user