You can now save presets to JSON and load them
This commit is contained in:
8
Reader.cs
Normal file
8
Reader.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
public Class1()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.2.32526.322
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Merge", "Test_Merge\Test_Merge.csproj", "{F6694884-3B45-4017-9C9A-A0AFFC508245}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BAFC8496-36AE-4539-94DE-0E505E7A8F93}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Test_Merge
|
||||
|
||||
public ConfigurationTool(Bitmap fullImage, Rectangle mainZoneDimensions)
|
||||
{
|
||||
MainZone = new Zone(fullImage, mainZoneDimensions);
|
||||
MainZone = new Zone(fullImage, mainZoneDimensions,"Main");
|
||||
AutoCalibrate();
|
||||
}
|
||||
public void ResetMainZone()
|
||||
@@ -29,7 +29,7 @@ namespace Test_Merge
|
||||
{
|
||||
MainZone.ResetWindows();
|
||||
}
|
||||
public void SaveToJson(List<string> drivers,string configName)
|
||||
public void SaveToJson(List<string> drivers, string configName)
|
||||
{
|
||||
string JSON = "";
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Test_Merge
|
||||
JSON += MainZone.ToJSON() + "," + Environment.NewLine;
|
||||
JSON += "\"Drivers\":[" + Environment.NewLine;
|
||||
|
||||
for (int i = 0; i < drivers.Count;i++)
|
||||
for (int i = 0; i < drivers.Count; i++)
|
||||
{
|
||||
JSON += "\"" + drivers[i] + "\"";
|
||||
if (i < drivers.Count - 1)
|
||||
@@ -49,16 +49,16 @@ namespace Test_Merge
|
||||
|
||||
JSON += "}";
|
||||
|
||||
if(!Directory.Exists(CONFIGS_FOLDER_NAME))
|
||||
if (!Directory.Exists(CONFIGS_FOLDER_NAME))
|
||||
Directory.CreateDirectory(CONFIGS_FOLDER_NAME);
|
||||
|
||||
string path = CONFIGS_FOLDER_NAME + configName;
|
||||
|
||||
if(File.Exists(path + ".json"))
|
||||
if (File.Exists(path + ".json"))
|
||||
{
|
||||
//We need to create a new name
|
||||
int count = 2;
|
||||
while(File.Exists(path + "_" + count + ".json"))
|
||||
while (File.Exists(path + "_" + count + ".json"))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Test_Merge
|
||||
path += ".json";
|
||||
}
|
||||
|
||||
File.WriteAllText(path,JSON);
|
||||
File.WriteAllText(path, JSON);
|
||||
}
|
||||
public void AddWindows(List<Rectangle> rectangles)
|
||||
{
|
||||
@@ -107,15 +107,15 @@ namespace Test_Merge
|
||||
break;
|
||||
case 7:
|
||||
//First zone should be the driver's First Sector
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 1, false));
|
||||
break;
|
||||
case 8:
|
||||
//First zone should be the driver's Second Sector
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 2, false));
|
||||
break;
|
||||
case 9:
|
||||
//First zone should be the driver's Position Sector
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], false));
|
||||
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i - 1], 3, false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,8 @@ namespace Test_Merge
|
||||
}
|
||||
} while (iter.Next(PageIteratorLevel.Word));
|
||||
}
|
||||
//DEBUG
|
||||
int i = 1;
|
||||
foreach (Rectangle Rectangle in detectedText)
|
||||
{
|
||||
Rectangle windowRectangle;
|
||||
@@ -174,7 +176,11 @@ namespace Test_Merge
|
||||
Point windowLocation = new Point(0, (Rectangle.Y + Rectangle.Height / 2) - windowSize.Height / 2);
|
||||
windowRectangle = new Rectangle(windowLocation, windowSize);
|
||||
//We add the driver zones
|
||||
MainZone.AddZone(new Zone(MainZone.ZoneImage, windowRectangle));
|
||||
Zone driverZone = new Zone(MainZone.ZoneImage, windowRectangle, "DriverZone");
|
||||
MainZone.AddZone(driverZone);
|
||||
|
||||
driverZone.ZoneImage.Save("Driver" + i+".png");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,21 +53,21 @@ namespace Test_Merge
|
||||
//Position
|
||||
result += "Position : " + Position + Environment.NewLine;
|
||||
//Gap
|
||||
result += "Gap to leader : " + OCRDecoder.ConvertMsToTime(GapToLeader) + Environment.NewLine;
|
||||
result += "GapToLeader : " + Reader.ConvertMsToTime(GapToLeader) + Environment.NewLine;
|
||||
//LapTime
|
||||
result += "Lap time : " + OCRDecoder.ConvertMsToTime(LapTime) + Environment.NewLine;
|
||||
result += "LapTime : " + 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;
|
||||
result += "DriverName : " + Name + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 1 : " + OCRDecoder.ConvertMsToTime(Sector1) + Environment.NewLine;
|
||||
result += "Sector1 : " + Reader.ConvertMsToTime(Sector1) + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 2 : " + OCRDecoder.ConvertMsToTime(Sector2) + Environment.NewLine;
|
||||
result += "Sector2 : " + Reader.ConvertMsToTime(Sector2) + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 3 : " + OCRDecoder.ConvertMsToTime(Sector3) + Environment.NewLine;
|
||||
result += "Sector3 : " + Reader.ConvertMsToTime(Sector3) + Environment.NewLine;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Test_Merge
|
||||
{
|
||||
public DriverGapToLeaderWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
|
||||
{
|
||||
Name = "Gap to leader";
|
||||
Name = "GapToLeader";
|
||||
}
|
||||
/// <summary>
|
||||
/// Decodes the gap to leader using Tesseract OCR
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Test_Merge
|
||||
{
|
||||
public DriverLapTimeWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
|
||||
{
|
||||
Name = "Lap time";
|
||||
Name = "LapTime";
|
||||
}
|
||||
/// <summary>
|
||||
/// Decodes the lap time contained in the image using OCR Tesseract
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace Test_Merge
|
||||
{
|
||||
internal class DriverSectorWindow:Window
|
||||
{
|
||||
public DriverSectorWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
|
||||
public DriverSectorWindow(Bitmap image, Rectangle bounds, int sectorId, bool generateEngine = true) : base(image, bounds,generateEngine)
|
||||
{
|
||||
Name = "Sector 1";
|
||||
Name = "Sector"+sectorId;
|
||||
}
|
||||
/// <summary>
|
||||
/// Decodes the sector
|
||||
|
||||
@@ -1,76 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Test_Merge
|
||||
{
|
||||
internal class OCRDecoder
|
||||
public class Reader
|
||||
{
|
||||
private string _configFile;
|
||||
private string _imagesFolder;
|
||||
private List<string> _drivers;
|
||||
private List<Zone> _mainZones;
|
||||
private Bitmap FullImage;
|
||||
public string ConfigFile { get => _configFile; private set => _configFile = value; }
|
||||
public string ImagesFolder { get => _imagesFolder; private set => _imagesFolder = value; }
|
||||
public List<string> Drivers { get => _drivers; private set => _drivers = value; }
|
||||
public List<Zone> MainZones { get => _mainZones; set => _mainZones = value; }
|
||||
|
||||
//All the image infos will be deleted in not too much time when the merge with the program that recovers the images
|
||||
const string DEFAULT_IMAGE_NAME = "screen_";
|
||||
// You will defenitely have to change this if you want to be able to see debug images
|
||||
public const string DEBUG_DUMP_FOLDER = @"C:\Users\Moi\Desktop\imgDump\Decode\";
|
||||
const int NUMBER_OF_DRIVERS = 20;
|
||||
public List<string> Drivers;
|
||||
public List<Zone> MainZones;
|
||||
|
||||
public OCRDecoder(string configFile, string imageFolder)
|
||||
public Reader(string configFile, Bitmap image,bool loadOCR = true)
|
||||
{
|
||||
ConfigFile = configFile;
|
||||
ImagesFolder = imageFolder;
|
||||
Load(82);
|
||||
MainZones = Load(image,configFile,ref Drivers,loadOCR);
|
||||
}
|
||||
/// <summary>
|
||||
/// Method that reads the JSON config file and create all the Zones and Windows
|
||||
/// </summary>
|
||||
/// <param name="imageNumber">The image #id on wich you want to create the zones on</param>
|
||||
private void Load(int imageNumber)
|
||||
public static List<Zone> Load(Bitmap image,string configFilePath,ref List<string> driverListToFill,bool LoadOCR)
|
||||
{
|
||||
MainZones = new List<Zone>();
|
||||
try
|
||||
{
|
||||
FullImage = (Bitmap)Image.FromFile(ImagesFolder + DEFAULT_IMAGE_NAME + imageNumber + ".png");
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Trouble reaching the image");
|
||||
//Maybe a bit to harsh, Ill see what I can do to soft this a bit
|
||||
Application.Exit();
|
||||
}
|
||||
List<Zone> mainZones = new List<Zone>();
|
||||
Bitmap fullImage = image;
|
||||
List<string> drivers;
|
||||
Zone mainZone;
|
||||
|
||||
Zone MainZone;
|
||||
try
|
||||
{
|
||||
using (var streamReader = new StreamReader(ConfigFile))
|
||||
using (var streamReader = new StreamReader(configFilePath))
|
||||
{
|
||||
var jsonText = streamReader.ReadToEnd();
|
||||
var jsonDocument = JsonDocument.Parse(jsonText);
|
||||
|
||||
var driversNames = jsonDocument.RootElement.GetProperty("Drivers");
|
||||
Drivers = new List<string>();
|
||||
driverListToFill = new List<string>();
|
||||
|
||||
foreach (var nameElement in driversNames.EnumerateArray())
|
||||
{
|
||||
Drivers.Add(nameElement.GetString());
|
||||
driverListToFill.Add(nameElement.GetString());
|
||||
}
|
||||
|
||||
var mainProperty = jsonDocument.RootElement.GetProperty("Main");
|
||||
Point MainPosition = new Point(mainProperty.GetProperty("x").GetInt32(), mainProperty.GetProperty("y").GetInt32());
|
||||
Size MainSize = new Size(mainProperty.GetProperty("width").GetInt32(), mainProperty.GetProperty("height").GetInt32());
|
||||
Rectangle MainRectangle = new Rectangle(MainPosition, MainSize);
|
||||
MainZone = new Zone(FullImage, MainRectangle);
|
||||
mainZone = new Zone(image, MainRectangle,"Main");
|
||||
|
||||
var zones = mainProperty.GetProperty("Zones");
|
||||
var driverZone = zones[0].GetProperty("DriverZone");
|
||||
@@ -80,7 +60,6 @@ namespace Test_Merge
|
||||
|
||||
var windows = driverZone.GetProperty("Windows");
|
||||
|
||||
//var driverPosition = windows.GetProperty("Position");
|
||||
var driverPosition = windows[0].GetProperty("Position");
|
||||
Size driverPositionArea = new Size(driverPosition.GetProperty("width").GetInt32(), FirstZoneSize.Height);
|
||||
Point driverPositionPosition = new Point(driverPosition.GetProperty("x").GetInt32(), driverPosition.GetProperty("y").GetInt32());
|
||||
@@ -94,7 +73,7 @@ namespace Test_Merge
|
||||
Point driverLapTimePosition = new Point(driverLapTime.GetProperty("x").GetInt32(), driverLapTime.GetProperty("y").GetInt32());
|
||||
|
||||
|
||||
var driverDrs = windows[0].GetProperty("Drs");
|
||||
var driverDrs = windows[0].GetProperty("DRS");
|
||||
Size driverDrsArea = new Size(driverDrs.GetProperty("width").GetInt32(), FirstZoneSize.Height);
|
||||
Point driverDrsPosition = new Point(driverDrs.GetProperty("x").GetInt32(), driverDrs.GetProperty("y").GetInt32());
|
||||
|
||||
@@ -118,17 +97,19 @@ namespace Test_Merge
|
||||
Size driverSector3Area = new Size(driverSector3.GetProperty("width").GetInt32(), FirstZoneSize.Height);
|
||||
Point driverSector3Position = new Point(driverSector3.GetProperty("x").GetInt32(), driverSector3.GetProperty("y").GetInt32());
|
||||
|
||||
float offset = (((float)MainZone.ZoneImage.Height - (float)(Drivers.Count * FirstZoneSize.Height)) / (float)Drivers.Count);
|
||||
Bitmap MainZoneImage = MainZone.ZoneImage;
|
||||
float offset = (((float)mainZone.ZoneImage.Height - (float)(driverListToFill.Count * FirstZoneSize.Height)) / (float)driverListToFill.Count);
|
||||
Bitmap MainZoneImage = mainZone.ZoneImage;
|
||||
List<Zone> zonesToAdd = new List<Zone>();
|
||||
List<Bitmap> zonesImages = new List<Bitmap>();
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_DRIVERS; i++)
|
||||
{
|
||||
Point tmpPos = new Point(0, FirstZonePosition.Y + i * FirstZoneSize.Height - Convert.ToInt32(i * offset));
|
||||
Zone newDriverZone = new Zone(MainZoneImage, new Rectangle(tmpPos, FirstZoneSize));
|
||||
Zone newDriverZone = new Zone(MainZoneImage, new Rectangle(tmpPos, FirstZoneSize), "DriverZone");
|
||||
zonesToAdd.Add(newDriverZone);
|
||||
zonesImages.Add(newDriverZone.ZoneImage);
|
||||
|
||||
newDriverZone.ZoneImage.Save("Driver"+i+".png");
|
||||
}
|
||||
|
||||
//Parallel.For(0, NUMBER_OF_DRIVERS, i =>
|
||||
@@ -137,20 +118,20 @@ namespace Test_Merge
|
||||
Zone newDriverZone = zonesToAdd[(int)i];
|
||||
Bitmap zoneImg = zonesImages[(int)i];
|
||||
|
||||
newDriverZone.AddWindow(new DriverPositionWindow(zoneImg, new Rectangle(driverPositionPosition, driverPositionArea)));
|
||||
newDriverZone.AddWindow(new DriverGapToLeaderWindow(zoneImg, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea)));
|
||||
newDriverZone.AddWindow(new DriverLapTimeWindow(zoneImg, new Rectangle(driverLapTimePosition, driverLapTimeArea)));
|
||||
newDriverZone.AddWindow(new DriverDrsWindow(zoneImg, new Rectangle(driverDrsPosition, driverDrsArea)));
|
||||
newDriverZone.AddWindow(new DriverTyresWindow(zoneImg, new Rectangle(driverTyresPosition, driverTyresArea)));
|
||||
newDriverZone.AddWindow(new DriverNameWindow(zoneImg, new Rectangle(driverNamePosition, driverNameArea)));
|
||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector1Position, driverSector1Area)));
|
||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector2Position, driverSector2Area)));
|
||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector3Position, driverSector3Area)));
|
||||
newDriverZone.AddWindow(new DriverPositionWindow(zoneImg, new Rectangle(driverPositionPosition, driverPositionArea),LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverGapToLeaderWindow(zoneImg, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea), LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverLapTimeWindow(zoneImg, new Rectangle(driverLapTimePosition, driverLapTimeArea), LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverDrsWindow(zoneImg, new Rectangle(driverDrsPosition, driverDrsArea), LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverTyresWindow(zoneImg, new Rectangle(driverTyresPosition, driverTyresArea), LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverNameWindow(zoneImg, new Rectangle(driverNamePosition, driverNameArea), LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector1Position, driverSector1Area),1, LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector2Position, driverSector2Area),2, LoadOCR));
|
||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector3Position, driverSector3Area),3, LoadOCR));
|
||||
|
||||
MainZone.AddZone(newDriverZone);
|
||||
mainZone.AddZone(newDriverZone);
|
||||
}//);
|
||||
//MessageBox.Show("We have a main zone with " + MainZone.Zones.Count() + " Driver zones with " + MainZone.Zones[4].Windows.Count() + " windows each and we have " + Drivers.Count + " drivers");
|
||||
MainZones.Add(MainZone);
|
||||
mainZones.Add(mainZone);
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
@@ -161,51 +142,26 @@ namespace Test_Merge
|
||||
{
|
||||
MessageBox.Show("Invalid JSON format: " + ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Changes the zones and windows to the new image
|
||||
/// </summary>
|
||||
/// <param name="imageNumber">The #id of the new image on wich to do OCR</param>
|
||||
public void ChangeImage(int imageNumber)
|
||||
{
|
||||
Bitmap img = null;
|
||||
string imagePath = ImagesFolder + DEFAULT_IMAGE_NAME + imageNumber + ".png";
|
||||
try
|
||||
{
|
||||
img = (Bitmap)Image.FromFile(imagePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Unable to reach the image at " + imagePath);
|
||||
}
|
||||
if (img != null)
|
||||
{
|
||||
FullImage = img;
|
||||
foreach (Zone z in MainZones)
|
||||
{
|
||||
z.Image = img;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mainZones;
|
||||
}
|
||||
/// <summary>
|
||||
/// Method that calls all the zones and windows to get the content they can find on the image to display them
|
||||
/// </summary>
|
||||
/// <param name="idImage">The id of the image we are working with</param>
|
||||
/// <returns>a string representation of all the returns</returns>
|
||||
public async Task<string> Decode(int idImage)
|
||||
public async Task<string> Decode(List<Zone> mainZones,List<string> drivers)
|
||||
{
|
||||
string result = "";
|
||||
ChangeImage(idImage);
|
||||
List<DriverData> mainResults = new List<DriverData>();
|
||||
|
||||
//Decode
|
||||
for (int mainZoneId = 0; mainZoneId < MainZones.Count; mainZoneId++)
|
||||
for (int mainZoneId = 0; mainZoneId < mainZones.Count; mainZoneId++)
|
||||
{
|
||||
switch (mainZoneId)
|
||||
{
|
||||
case 0:
|
||||
//Main Zone
|
||||
foreach (Zone z in MainZones[mainZoneId].Zones)
|
||||
foreach (Zone z in mainZones[mainZoneId].Zones)
|
||||
{
|
||||
mainResults.Add(await z.Decode(Drivers));
|
||||
}
|
||||
@@ -242,22 +198,12 @@ namespace Test_Merge
|
||||
/// </summary>
|
||||
/// <param name="idImage">the #id of the image we are working with</param>
|
||||
/// <returns>the drawed bitmap</returns>
|
||||
public Bitmap Draw(int idImage)
|
||||
public Bitmap Draw(Bitmap image,List<Zone> mainZones)
|
||||
{
|
||||
Bitmap result;
|
||||
try
|
||||
{
|
||||
result = (Bitmap)Image.FromFile(ImagesFolder + DEFAULT_IMAGE_NAME + idImage + ".png");
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Image could not be found");
|
||||
return null;
|
||||
}
|
||||
|
||||
Graphics g = Graphics.FromImage(result);
|
||||
Graphics g = Graphics.FromImage(image);
|
||||
|
||||
foreach (Zone z in MainZones)
|
||||
foreach (Zone z in mainZones)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (Zone zz in z.Zones)
|
||||
@@ -272,7 +218,7 @@ namespace Test_Merge
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Test_Merge/Settings.Designer.cs
generated
20
Test_Merge/Settings.Designer.cs
generated
@@ -57,6 +57,7 @@
|
||||
this.btnCreateWindow = new System.Windows.Forms.Button();
|
||||
this.btnCreatZone = new System.Windows.Forms.Button();
|
||||
this.btnResetDriver = new System.Windows.Forms.Button();
|
||||
this.btnLoadPreset = new System.Windows.Forms.Button();
|
||||
this.gpbxInfos.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
@@ -260,6 +261,7 @@
|
||||
//
|
||||
// groupBox4
|
||||
//
|
||||
this.groupBox4.Controls.Add(this.btnLoadPreset);
|
||||
this.groupBox4.Controls.Add(this.label8);
|
||||
this.groupBox4.Controls.Add(this.lsbPresets);
|
||||
this.groupBox4.Controls.Add(this.tbxPresetName);
|
||||
@@ -280,7 +282,7 @@
|
||||
// label8
|
||||
//
|
||||
this.label8.AutoSize = true;
|
||||
this.label8.Location = new System.Drawing.Point(6, 314);
|
||||
this.label8.Location = new System.Drawing.Point(6, 337);
|
||||
this.label8.Name = "label8";
|
||||
this.label8.Size = new System.Drawing.Size(68, 23);
|
||||
this.label8.TabIndex = 9;
|
||||
@@ -290,10 +292,11 @@
|
||||
//
|
||||
this.lsbPresets.FormattingEnabled = true;
|
||||
this.lsbPresets.ItemHeight = 23;
|
||||
this.lsbPresets.Location = new System.Drawing.Point(10, 340);
|
||||
this.lsbPresets.Location = new System.Drawing.Point(10, 363);
|
||||
this.lsbPresets.Name = "lsbPresets";
|
||||
this.lsbPresets.Size = new System.Drawing.Size(197, 257);
|
||||
this.lsbPresets.Size = new System.Drawing.Size(197, 234);
|
||||
this.lsbPresets.TabIndex = 8;
|
||||
this.lsbPresets.SelectedIndexChanged += new System.EventHandler(this.lsbPresets_SelectedIndexChanged);
|
||||
//
|
||||
// tbxPresetName
|
||||
//
|
||||
@@ -370,6 +373,16 @@
|
||||
this.btnResetDriver.UseVisualStyleBackColor = true;
|
||||
this.btnResetDriver.Click += new System.EventHandler(this.btnResetDriver_Click);
|
||||
//
|
||||
// btnLoadPreset
|
||||
//
|
||||
this.btnLoadPreset.Location = new System.Drawing.Point(6, 297);
|
||||
this.btnLoadPreset.Name = "btnLoadPreset";
|
||||
this.btnLoadPreset.Size = new System.Drawing.Size(201, 40);
|
||||
this.btnLoadPreset.TabIndex = 10;
|
||||
this.btnLoadPreset.Text = "LoadPreset";
|
||||
this.btnLoadPreset.UseVisualStyleBackColor = true;
|
||||
this.btnLoadPreset.Click += new System.EventHandler(this.btnLoadPreset_Click);
|
||||
//
|
||||
// Settings
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 19F);
|
||||
@@ -433,5 +446,6 @@
|
||||
private System.Windows.Forms.Label label8;
|
||||
private System.Windows.Forms.Button btnRefresh;
|
||||
private System.Windows.Forms.Button btnResetDriver;
|
||||
private System.Windows.Forms.Button btnLoadPreset;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ namespace Test_Merge
|
||||
}
|
||||
private void RefreshUI()
|
||||
{
|
||||
|
||||
lsbDrivers.DataSource = null;
|
||||
lsbDrivers.DataSource = DriverList;
|
||||
|
||||
@@ -385,5 +386,30 @@ namespace Test_Merge
|
||||
}
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
private void lsbPresets_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
//Nothing
|
||||
}
|
||||
|
||||
private void btnLoadPreset_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (lsbPresets.SelectedIndex >= 0 && pbxMain.Image != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Reader reader = new Reader(lsbPresets.Items[lsbPresets.SelectedIndex].ToString(), (Bitmap)pbxMain.Image,false);
|
||||
//MainZones #0 is the big main zone containing driver zones
|
||||
Config = new ConfigurationTool((Bitmap)pbxMain.Image, reader.MainZones[0].Bounds);
|
||||
Config.MainZone = reader.MainZones[0];
|
||||
DriverList = reader.Drivers;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Could not load the settings error :" + ex);
|
||||
}
|
||||
RefreshUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,10 +102,10 @@
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="OCRDecoder.cs" />
|
||||
<Compile Include="OcrImage.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Reader.cs" />
|
||||
<Compile Include="Settings.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Test_Merge
|
||||
private List<Zone> _zones;
|
||||
private List<Window> _windows;
|
||||
private Bitmap _image;
|
||||
private string _name;
|
||||
|
||||
public Bitmap ZoneImage
|
||||
{
|
||||
@@ -46,11 +47,13 @@ namespace Test_Merge
|
||||
public Rectangle Bounds { get => _bounds; protected set => _bounds = value; }
|
||||
public List<Zone> Zones { get => _zones; protected set => _zones = value; }
|
||||
public List<Window> Windows { get => _windows; protected set => _windows = value; }
|
||||
public string Name { get => _name; protected set => _name = value; }
|
||||
|
||||
public Zone(Bitmap image, Rectangle bounds)
|
||||
public Zone(Bitmap image, Rectangle bounds, string name)
|
||||
{
|
||||
Windows = new List<Window>();
|
||||
Zones = new List<Zone>();
|
||||
Name = name;
|
||||
|
||||
//You cant set the image in the CTOR because the processing is impossible at first initiation
|
||||
_image = image;
|
||||
@@ -97,13 +100,13 @@ namespace Test_Merge
|
||||
if (w is DriverSectorWindow)
|
||||
{
|
||||
sectorCount++;
|
||||
if (sectorCount == 1)
|
||||
if (sectorCount == 1)
|
||||
result.Sector1 = (int)await (w as DriverSectorWindow).DecodePng();
|
||||
if (sectorCount == 2)
|
||||
result.Sector2 = (int)await (w as DriverSectorWindow).DecodePng();
|
||||
if (sectorCount == 3)
|
||||
result.Sector3 = (int)await (w as DriverSectorWindow).DecodePng();
|
||||
}
|
||||
}
|
||||
if (w is DriverTyresWindow)
|
||||
result.CurrentTyre = (Tyre)await (w as DriverTyresWindow).DecodePng();
|
||||
});
|
||||
@@ -122,16 +125,16 @@ namespace Test_Merge
|
||||
{
|
||||
img = ZoneImage;
|
||||
}
|
||||
|
||||
|
||||
Graphics g = Graphics.FromImage(img);
|
||||
|
||||
//If its the main zone we need to visualize the Zone bounds displayed
|
||||
if (Zones.Count > 0)
|
||||
g.DrawRectangle(new Pen(Brushes.Violet,5),Bounds);
|
||||
g.DrawRectangle(new Pen(Brushes.Violet, 5), Bounds);
|
||||
|
||||
foreach (Zone z in Zones)
|
||||
{
|
||||
Rectangle newBounds = new Rectangle(z.Bounds.X,z.Bounds.Y + Bounds.Y,z.Bounds.Width,z.Bounds.Height);
|
||||
Rectangle newBounds = new Rectangle(z.Bounds.X, z.Bounds.Y + Bounds.Y, z.Bounds.Width, z.Bounds.Height);
|
||||
g.DrawRectangle(Pens.Red, newBounds);
|
||||
}
|
||||
foreach (Window w in Windows)
|
||||
@@ -155,7 +158,7 @@ namespace Test_Merge
|
||||
public virtual string ToJSON()
|
||||
{
|
||||
string result = "";
|
||||
result += "\"" + "Zone" + "\":{" + Environment.NewLine;
|
||||
result += "\"" + Name + "\":{" + Environment.NewLine;
|
||||
result += "\t" + "\"x\":" + Bounds.X + "," + Environment.NewLine;
|
||||
result += "\t" + "\"y\":" + Bounds.Y + "," + Environment.NewLine;
|
||||
result += "\t" + "\"width\":" + Bounds.Width + "," + Environment.NewLine;
|
||||
|
||||
Reference in New Issue
Block a user