Fixed the calibration and added the JSON serialising

This commit is contained in:
2023-05-05 15:00:39 +02:00
parent 2c2239427c
commit 16be9bf7ef
13 changed files with 205 additions and 72 deletions

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tesseract;
using System.IO;
namespace Test_Merge
{
@@ -13,12 +14,63 @@ namespace Test_Merge
public Zone MainZone;
public const int NUMBER_OF_DRIVERS = 20;
public const int NUMBER_OF_ZONES = 9;
public const string CONFIGS_FOLDER_NAME = "./Presets/";
public ConfigurationTool(Bitmap fullImage,Rectangle mainZoneDimensions)
public ConfigurationTool(Bitmap fullImage, Rectangle mainZoneDimensions)
{
MainZone = new Zone(fullImage,mainZoneDimensions);
MainZone = new Zone(fullImage, mainZoneDimensions);
AutoCalibrate();
}
public void ResetMainZone()
{
MainZone.ResetZones();
}
public void ResetWindows()
{
MainZone.ResetWindows();
}
public void SaveToJson(List<string> drivers,string configName)
{
string JSON = "";
JSON += "{" + Environment.NewLine;
JSON += MainZone.ToJSON() + "," + Environment.NewLine;
JSON += "\"Drivers\":[" + Environment.NewLine;
for (int i = 0; i < drivers.Count;i++)
{
JSON += "\"" + drivers[i] + "\"";
if (i < drivers.Count - 1)
JSON += ",";
JSON += Environment.NewLine;
}
JSON += "]" + Environment.NewLine;
JSON += "}";
if(!Directory.Exists(CONFIGS_FOLDER_NAME))
Directory.CreateDirectory(CONFIGS_FOLDER_NAME);
string path = CONFIGS_FOLDER_NAME + configName;
if(File.Exists(path + ".json"))
{
//We need to create a new name
int count = 2;
while(File.Exists(path + "_" + count + ".json"))
{
count++;
}
path += "_" + count + ".json";
}
else
{
path += ".json";
}
File.WriteAllText(path,JSON);
}
public void AddWindows(List<Rectangle> rectangles)
{
foreach (Zone driverZone in MainZone.Zones)
@@ -31,39 +83,39 @@ namespace Test_Merge
{
case 1:
//First zone should be the driver's Position
driverZone.AddWindow(new DriverPositionWindow(driverZone.ZoneImage, rectangles[i]));
driverZone.AddWindow(new DriverPositionWindow(driverZone.ZoneImage, rectangles[i - 1], false));
break;
case 2:
//First zone should be the driver's Position
driverZone.AddWindow(new DriverGapToLeaderWindow(driverZone.ZoneImage, rectangles[i]));
//First 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 Position
driverZone.AddWindow(new DriverLapTimeWindow(driverZone.ZoneImage, rectangles[i]));
//First 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 Position
driverZone.AddWindow(new DriverDrsWindow(driverZone.ZoneImage, rectangles[i]));
//First 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 Position
driverZone.AddWindow(new DriverTyresWindow(driverZone.ZoneImage, rectangles[i]));
//First 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 Position
driverZone.AddWindow(new DriverNameWindow(driverZone.ZoneImage, rectangles[i]));
//First 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 Position
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i]));
//First zone should be the driver's First Sector
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false));
break;
case 8:
//First zone should be the driver's Position
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i]));
//First zone should be the driver's Second Sector
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false));
break;
case 9:
//First zone should be the driver's Position
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i]));
//First zone should be the driver's Position Sector
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false));
break;
}
}