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
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Merge", "Test_Merge\Test_Merge.csproj", "{F6694884-3B45-4017-9C9A-A0AFFC508245}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Merge", "Test_Merge\Test_Merge.csproj", "{F6694884-3B45-4017-9C9A-A0AFFC508245}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BAFC8496-36AE-4539-94DE-0E505E7A8F93}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Test_Merge
|
|||||||
|
|
||||||
public ConfigurationTool(Bitmap fullImage, Rectangle mainZoneDimensions)
|
public ConfigurationTool(Bitmap fullImage, Rectangle mainZoneDimensions)
|
||||||
{
|
{
|
||||||
MainZone = new Zone(fullImage, mainZoneDimensions);
|
MainZone = new Zone(fullImage, mainZoneDimensions,"Main");
|
||||||
AutoCalibrate();
|
AutoCalibrate();
|
||||||
}
|
}
|
||||||
public void ResetMainZone()
|
public void ResetMainZone()
|
||||||
@@ -29,7 +29,7 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
MainZone.ResetWindows();
|
MainZone.ResetWindows();
|
||||||
}
|
}
|
||||||
public void SaveToJson(List<string> drivers,string configName)
|
public void SaveToJson(List<string> drivers, string configName)
|
||||||
{
|
{
|
||||||
string JSON = "";
|
string JSON = "";
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ namespace Test_Merge
|
|||||||
JSON += MainZone.ToJSON() + "," + Environment.NewLine;
|
JSON += MainZone.ToJSON() + "," + Environment.NewLine;
|
||||||
JSON += "\"Drivers\":[" + 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] + "\"";
|
JSON += "\"" + drivers[i] + "\"";
|
||||||
if (i < drivers.Count - 1)
|
if (i < drivers.Count - 1)
|
||||||
@@ -49,16 +49,16 @@ namespace Test_Merge
|
|||||||
|
|
||||||
JSON += "}";
|
JSON += "}";
|
||||||
|
|
||||||
if(!Directory.Exists(CONFIGS_FOLDER_NAME))
|
if (!Directory.Exists(CONFIGS_FOLDER_NAME))
|
||||||
Directory.CreateDirectory(CONFIGS_FOLDER_NAME);
|
Directory.CreateDirectory(CONFIGS_FOLDER_NAME);
|
||||||
|
|
||||||
string path = CONFIGS_FOLDER_NAME + configName;
|
string path = CONFIGS_FOLDER_NAME + configName;
|
||||||
|
|
||||||
if(File.Exists(path + ".json"))
|
if (File.Exists(path + ".json"))
|
||||||
{
|
{
|
||||||
//We need to create a new name
|
//We need to create a new name
|
||||||
int count = 2;
|
int count = 2;
|
||||||
while(File.Exists(path + "_" + count + ".json"))
|
while (File.Exists(path + "_" + count + ".json"))
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ namespace Test_Merge
|
|||||||
path += ".json";
|
path += ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllText(path,JSON);
|
File.WriteAllText(path, JSON);
|
||||||
}
|
}
|
||||||
public void AddWindows(List<Rectangle> rectangles)
|
public void AddWindows(List<Rectangle> rectangles)
|
||||||
{
|
{
|
||||||
@@ -107,15 +107,15 @@ namespace Test_Merge
|
|||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
//First zone should be the driver's First Sector
|
//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;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
//First zone should be the driver's Second Sector
|
//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;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
//First zone should be the driver's Position Sector
|
//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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,6 +167,8 @@ namespace Test_Merge
|
|||||||
}
|
}
|
||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} while (iter.Next(PageIteratorLevel.Word));
|
||||||
}
|
}
|
||||||
|
//DEBUG
|
||||||
|
int i = 1;
|
||||||
foreach (Rectangle Rectangle in detectedText)
|
foreach (Rectangle Rectangle in detectedText)
|
||||||
{
|
{
|
||||||
Rectangle windowRectangle;
|
Rectangle windowRectangle;
|
||||||
@@ -174,7 +176,11 @@ namespace Test_Merge
|
|||||||
Point windowLocation = new Point(0, (Rectangle.Y + Rectangle.Height / 2) - windowSize.Height / 2);
|
Point windowLocation = new Point(0, (Rectangle.Y + Rectangle.Height / 2) - windowSize.Height / 2);
|
||||||
windowRectangle = new Rectangle(windowLocation, windowSize);
|
windowRectangle = new Rectangle(windowLocation, windowSize);
|
||||||
//We add the driver zones
|
//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
|
//Position
|
||||||
result += "Position : " + Position + Environment.NewLine;
|
result += "Position : " + Position + Environment.NewLine;
|
||||||
//Gap
|
//Gap
|
||||||
result += "Gap to leader : " + OCRDecoder.ConvertMsToTime(GapToLeader) + Environment.NewLine;
|
result += "GapToLeader : " + Reader.ConvertMsToTime(GapToLeader) + Environment.NewLine;
|
||||||
//LapTime
|
//LapTime
|
||||||
result += "Lap time : " + OCRDecoder.ConvertMsToTime(LapTime) + Environment.NewLine;
|
result += "LapTime : " + Reader.ConvertMsToTime(LapTime) + Environment.NewLine;
|
||||||
//DRS
|
//DRS
|
||||||
result += "DRS : " + DRS + Environment.NewLine;
|
result += "DRS : " + DRS + Environment.NewLine;
|
||||||
//Tyres
|
//Tyres
|
||||||
result += "Uses " + CurrentTyre.Coumpound + " tyre " + CurrentTyre.NumberOfLaps + " laps old" + Environment.NewLine;
|
result += "Uses " + CurrentTyre.Coumpound + " tyre " + CurrentTyre.NumberOfLaps + " laps old" + Environment.NewLine;
|
||||||
//Name
|
//Name
|
||||||
result += "Driver name : " + Name + Environment.NewLine;
|
result += "DriverName : " + Name + Environment.NewLine;
|
||||||
//Sector 1
|
//Sector 1
|
||||||
result += "Sector 1 : " + OCRDecoder.ConvertMsToTime(Sector1) + Environment.NewLine;
|
result += "Sector1 : " + Reader.ConvertMsToTime(Sector1) + Environment.NewLine;
|
||||||
//Sector 1
|
//Sector 1
|
||||||
result += "Sector 2 : " + OCRDecoder.ConvertMsToTime(Sector2) + Environment.NewLine;
|
result += "Sector2 : " + Reader.ConvertMsToTime(Sector2) + Environment.NewLine;
|
||||||
//Sector 1
|
//Sector 1
|
||||||
result += "Sector 3 : " + OCRDecoder.ConvertMsToTime(Sector3) + Environment.NewLine;
|
result += "Sector3 : " + Reader.ConvertMsToTime(Sector3) + Environment.NewLine;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
public DriverGapToLeaderWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
|
public DriverGapToLeaderWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
|
||||||
{
|
{
|
||||||
Name = "Gap to leader";
|
Name = "GapToLeader";
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decodes the gap to leader using Tesseract OCR
|
/// 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)
|
public DriverLapTimeWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
|
||||||
{
|
{
|
||||||
Name = "Lap time";
|
Name = "LapTime";
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decodes the lap time contained in the image using OCR Tesseract
|
/// Decodes the lap time contained in the image using OCR Tesseract
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
internal class DriverSectorWindow:Window
|
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>
|
/// <summary>
|
||||||
/// Decodes the sector
|
/// Decodes the sector
|
||||||
|
|||||||
@@ -1,76 +1,56 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace Test_Merge
|
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;
|
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;
|
MainZones = Load(image,configFile,ref Drivers,loadOCR);
|
||||||
ImagesFolder = imageFolder;
|
|
||||||
Load(82);
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method that reads the JSON config file and create all the Zones and Windows
|
/// Method that reads the JSON config file and create all the Zones and Windows
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="imageNumber">The image #id on wich you want to create the zones on</param>
|
/// <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>();
|
List<Zone> mainZones = new List<Zone>();
|
||||||
try
|
Bitmap fullImage = image;
|
||||||
{
|
List<string> drivers;
|
||||||
FullImage = (Bitmap)Image.FromFile(ImagesFolder + DEFAULT_IMAGE_NAME + imageNumber + ".png");
|
Zone mainZone;
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
Zone MainZone;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var streamReader = new StreamReader(ConfigFile))
|
using (var streamReader = new StreamReader(configFilePath))
|
||||||
{
|
{
|
||||||
var jsonText = streamReader.ReadToEnd();
|
var jsonText = streamReader.ReadToEnd();
|
||||||
var jsonDocument = JsonDocument.Parse(jsonText);
|
var jsonDocument = JsonDocument.Parse(jsonText);
|
||||||
|
|
||||||
var driversNames = jsonDocument.RootElement.GetProperty("Drivers");
|
var driversNames = jsonDocument.RootElement.GetProperty("Drivers");
|
||||||
Drivers = new List<string>();
|
driverListToFill = new List<string>();
|
||||||
|
|
||||||
foreach (var nameElement in driversNames.EnumerateArray())
|
foreach (var nameElement in driversNames.EnumerateArray())
|
||||||
{
|
{
|
||||||
Drivers.Add(nameElement.GetString());
|
driverListToFill.Add(nameElement.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
var mainProperty = jsonDocument.RootElement.GetProperty("Main");
|
var mainProperty = jsonDocument.RootElement.GetProperty("Main");
|
||||||
Point MainPosition = new Point(mainProperty.GetProperty("x").GetInt32(), mainProperty.GetProperty("y").GetInt32());
|
Point MainPosition = new Point(mainProperty.GetProperty("x").GetInt32(), mainProperty.GetProperty("y").GetInt32());
|
||||||
Size MainSize = new Size(mainProperty.GetProperty("width").GetInt32(), mainProperty.GetProperty("height").GetInt32());
|
Size MainSize = new Size(mainProperty.GetProperty("width").GetInt32(), mainProperty.GetProperty("height").GetInt32());
|
||||||
Rectangle MainRectangle = new Rectangle(MainPosition, MainSize);
|
Rectangle MainRectangle = new Rectangle(MainPosition, MainSize);
|
||||||
MainZone = new Zone(FullImage, MainRectangle);
|
mainZone = new Zone(image, MainRectangle,"Main");
|
||||||
|
|
||||||
var zones = mainProperty.GetProperty("Zones");
|
var zones = mainProperty.GetProperty("Zones");
|
||||||
var driverZone = zones[0].GetProperty("DriverZone");
|
var driverZone = zones[0].GetProperty("DriverZone");
|
||||||
@@ -80,7 +60,6 @@ namespace Test_Merge
|
|||||||
|
|
||||||
var windows = driverZone.GetProperty("Windows");
|
var windows = driverZone.GetProperty("Windows");
|
||||||
|
|
||||||
//var driverPosition = windows.GetProperty("Position");
|
|
||||||
var driverPosition = windows[0].GetProperty("Position");
|
var driverPosition = windows[0].GetProperty("Position");
|
||||||
Size driverPositionArea = new Size(driverPosition.GetProperty("width").GetInt32(), FirstZoneSize.Height);
|
Size driverPositionArea = new Size(driverPosition.GetProperty("width").GetInt32(), FirstZoneSize.Height);
|
||||||
Point driverPositionPosition = new Point(driverPosition.GetProperty("x").GetInt32(), driverPosition.GetProperty("y").GetInt32());
|
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());
|
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);
|
Size driverDrsArea = new Size(driverDrs.GetProperty("width").GetInt32(), FirstZoneSize.Height);
|
||||||
Point driverDrsPosition = new Point(driverDrs.GetProperty("x").GetInt32(), driverDrs.GetProperty("y").GetInt32());
|
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);
|
Size driverSector3Area = new Size(driverSector3.GetProperty("width").GetInt32(), FirstZoneSize.Height);
|
||||||
Point driverSector3Position = new Point(driverSector3.GetProperty("x").GetInt32(), driverSector3.GetProperty("y").GetInt32());
|
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);
|
float offset = (((float)mainZone.ZoneImage.Height - (float)(driverListToFill.Count * FirstZoneSize.Height)) / (float)driverListToFill.Count);
|
||||||
Bitmap MainZoneImage = MainZone.ZoneImage;
|
Bitmap MainZoneImage = mainZone.ZoneImage;
|
||||||
List<Zone> zonesToAdd = new List<Zone>();
|
List<Zone> zonesToAdd = new List<Zone>();
|
||||||
List<Bitmap> zonesImages = new List<Bitmap>();
|
List<Bitmap> zonesImages = new List<Bitmap>();
|
||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_DRIVERS; i++)
|
for (int i = 0; i < NUMBER_OF_DRIVERS; i++)
|
||||||
{
|
{
|
||||||
Point tmpPos = new Point(0, FirstZonePosition.Y + i * FirstZoneSize.Height - Convert.ToInt32(i * offset));
|
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);
|
zonesToAdd.Add(newDriverZone);
|
||||||
zonesImages.Add(newDriverZone.ZoneImage);
|
zonesImages.Add(newDriverZone.ZoneImage);
|
||||||
|
|
||||||
|
newDriverZone.ZoneImage.Save("Driver"+i+".png");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Parallel.For(0, NUMBER_OF_DRIVERS, i =>
|
//Parallel.For(0, NUMBER_OF_DRIVERS, i =>
|
||||||
@@ -137,20 +118,20 @@ namespace Test_Merge
|
|||||||
Zone newDriverZone = zonesToAdd[(int)i];
|
Zone newDriverZone = zonesToAdd[(int)i];
|
||||||
Bitmap zoneImg = zonesImages[(int)i];
|
Bitmap zoneImg = zonesImages[(int)i];
|
||||||
|
|
||||||
newDriverZone.AddWindow(new DriverPositionWindow(zoneImg, new Rectangle(driverPositionPosition, driverPositionArea)));
|
newDriverZone.AddWindow(new DriverPositionWindow(zoneImg, new Rectangle(driverPositionPosition, driverPositionArea),LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverGapToLeaderWindow(zoneImg, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea)));
|
newDriverZone.AddWindow(new DriverGapToLeaderWindow(zoneImg, new Rectangle(driverGapToLeaderPosition, driverGapToLeaderArea), LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverLapTimeWindow(zoneImg, new Rectangle(driverLapTimePosition, driverLapTimeArea)));
|
newDriverZone.AddWindow(new DriverLapTimeWindow(zoneImg, new Rectangle(driverLapTimePosition, driverLapTimeArea), LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverDrsWindow(zoneImg, new Rectangle(driverDrsPosition, driverDrsArea)));
|
newDriverZone.AddWindow(new DriverDrsWindow(zoneImg, new Rectangle(driverDrsPosition, driverDrsArea), LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverTyresWindow(zoneImg, new Rectangle(driverTyresPosition, driverTyresArea)));
|
newDriverZone.AddWindow(new DriverTyresWindow(zoneImg, new Rectangle(driverTyresPosition, driverTyresArea), LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverNameWindow(zoneImg, new Rectangle(driverNamePosition, driverNameArea)));
|
newDriverZone.AddWindow(new DriverNameWindow(zoneImg, new Rectangle(driverNamePosition, driverNameArea), LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector1Position, driverSector1Area)));
|
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector1Position, driverSector1Area),1, LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector2Position, driverSector2Area)));
|
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector2Position, driverSector2Area),2, LoadOCR));
|
||||||
newDriverZone.AddWindow(new DriverSectorWindow(zoneImg, new Rectangle(driverSector3Position, driverSector3Area)));
|
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");
|
//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)
|
catch (IOException ex)
|
||||||
@@ -161,51 +142,26 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
MessageBox.Show("Invalid JSON format: " + ex.Message);
|
MessageBox.Show("Invalid JSON format: " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
return mainZones;
|
||||||
/// <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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method that calls all the zones and windows to get the content they can find on the image to display them
|
/// Method that calls all the zones and windows to get the content they can find on the image to display them
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idImage">The id of the image we are working with</param>
|
/// <param name="idImage">The id of the image we are working with</param>
|
||||||
/// <returns>a string representation of all the returns</returns>
|
/// <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 = "";
|
string result = "";
|
||||||
ChangeImage(idImage);
|
|
||||||
List<DriverData> mainResults = new List<DriverData>();
|
List<DriverData> mainResults = new List<DriverData>();
|
||||||
|
|
||||||
//Decode
|
//Decode
|
||||||
for (int mainZoneId = 0; mainZoneId < MainZones.Count; mainZoneId++)
|
for (int mainZoneId = 0; mainZoneId < mainZones.Count; mainZoneId++)
|
||||||
{
|
{
|
||||||
switch (mainZoneId)
|
switch (mainZoneId)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
//Main Zone
|
//Main Zone
|
||||||
foreach (Zone z in MainZones[mainZoneId].Zones)
|
foreach (Zone z in mainZones[mainZoneId].Zones)
|
||||||
{
|
{
|
||||||
mainResults.Add(await z.Decode(Drivers));
|
mainResults.Add(await z.Decode(Drivers));
|
||||||
}
|
}
|
||||||
@@ -242,22 +198,12 @@ namespace Test_Merge
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idImage">the #id of the image we are working with</param>
|
/// <param name="idImage">the #id of the image we are working with</param>
|
||||||
/// <returns>the drawed bitmap</returns>
|
/// <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;
|
int count = 0;
|
||||||
foreach (Zone zz in z.Zones)
|
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.btnCreateWindow = new System.Windows.Forms.Button();
|
||||||
this.btnCreatZone = new System.Windows.Forms.Button();
|
this.btnCreatZone = new System.Windows.Forms.Button();
|
||||||
this.btnResetDriver = new System.Windows.Forms.Button();
|
this.btnResetDriver = new System.Windows.Forms.Button();
|
||||||
|
this.btnLoadPreset = new System.Windows.Forms.Button();
|
||||||
this.gpbxInfos.SuspendLayout();
|
this.gpbxInfos.SuspendLayout();
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.SuspendLayout();
|
||||||
this.groupBox2.SuspendLayout();
|
this.groupBox2.SuspendLayout();
|
||||||
@@ -260,6 +261,7 @@
|
|||||||
//
|
//
|
||||||
// groupBox4
|
// groupBox4
|
||||||
//
|
//
|
||||||
|
this.groupBox4.Controls.Add(this.btnLoadPreset);
|
||||||
this.groupBox4.Controls.Add(this.label8);
|
this.groupBox4.Controls.Add(this.label8);
|
||||||
this.groupBox4.Controls.Add(this.lsbPresets);
|
this.groupBox4.Controls.Add(this.lsbPresets);
|
||||||
this.groupBox4.Controls.Add(this.tbxPresetName);
|
this.groupBox4.Controls.Add(this.tbxPresetName);
|
||||||
@@ -280,7 +282,7 @@
|
|||||||
// label8
|
// label8
|
||||||
//
|
//
|
||||||
this.label8.AutoSize = true;
|
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.Name = "label8";
|
||||||
this.label8.Size = new System.Drawing.Size(68, 23);
|
this.label8.Size = new System.Drawing.Size(68, 23);
|
||||||
this.label8.TabIndex = 9;
|
this.label8.TabIndex = 9;
|
||||||
@@ -290,10 +292,11 @@
|
|||||||
//
|
//
|
||||||
this.lsbPresets.FormattingEnabled = true;
|
this.lsbPresets.FormattingEnabled = true;
|
||||||
this.lsbPresets.ItemHeight = 23;
|
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.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.TabIndex = 8;
|
||||||
|
this.lsbPresets.SelectedIndexChanged += new System.EventHandler(this.lsbPresets_SelectedIndexChanged);
|
||||||
//
|
//
|
||||||
// tbxPresetName
|
// tbxPresetName
|
||||||
//
|
//
|
||||||
@@ -370,6 +373,16 @@
|
|||||||
this.btnResetDriver.UseVisualStyleBackColor = true;
|
this.btnResetDriver.UseVisualStyleBackColor = true;
|
||||||
this.btnResetDriver.Click += new System.EventHandler(this.btnResetDriver_Click);
|
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
|
// Settings
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 19F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 19F);
|
||||||
@@ -433,5 +446,6 @@
|
|||||||
private System.Windows.Forms.Label label8;
|
private System.Windows.Forms.Label label8;
|
||||||
private System.Windows.Forms.Button btnRefresh;
|
private System.Windows.Forms.Button btnRefresh;
|
||||||
private System.Windows.Forms.Button btnResetDriver;
|
private System.Windows.Forms.Button btnResetDriver;
|
||||||
|
private System.Windows.Forms.Button btnLoadPreset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,7 @@ namespace Test_Merge
|
|||||||
}
|
}
|
||||||
private void RefreshUI()
|
private void RefreshUI()
|
||||||
{
|
{
|
||||||
|
|
||||||
lsbDrivers.DataSource = null;
|
lsbDrivers.DataSource = null;
|
||||||
lsbDrivers.DataSource = DriverList;
|
lsbDrivers.DataSource = DriverList;
|
||||||
|
|
||||||
@@ -385,5 +386,30 @@ namespace Test_Merge
|
|||||||
}
|
}
|
||||||
RefreshUI();
|
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">
|
<Compile Include="Form1.Designer.cs">
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="OCRDecoder.cs" />
|
|
||||||
<Compile Include="OcrImage.cs" />
|
<Compile Include="OcrImage.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Reader.cs" />
|
||||||
<Compile Include="Settings.cs">
|
<Compile Include="Settings.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Test_Merge
|
|||||||
private List<Zone> _zones;
|
private List<Zone> _zones;
|
||||||
private List<Window> _windows;
|
private List<Window> _windows;
|
||||||
private Bitmap _image;
|
private Bitmap _image;
|
||||||
|
private string _name;
|
||||||
|
|
||||||
public Bitmap ZoneImage
|
public Bitmap ZoneImage
|
||||||
{
|
{
|
||||||
@@ -46,11 +47,13 @@ namespace Test_Merge
|
|||||||
public Rectangle Bounds { get => _bounds; protected set => _bounds = value; }
|
public Rectangle Bounds { get => _bounds; protected set => _bounds = value; }
|
||||||
public List<Zone> Zones { get => _zones; protected set => _zones = value; }
|
public List<Zone> Zones { get => _zones; protected set => _zones = value; }
|
||||||
public List<Window> Windows { get => _windows; protected set => _windows = 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>();
|
Windows = new List<Window>();
|
||||||
Zones = new List<Zone>();
|
Zones = new List<Zone>();
|
||||||
|
Name = name;
|
||||||
|
|
||||||
//You cant set the image in the CTOR because the processing is impossible at first initiation
|
//You cant set the image in the CTOR because the processing is impossible at first initiation
|
||||||
_image = image;
|
_image = image;
|
||||||
@@ -127,11 +130,11 @@ namespace Test_Merge
|
|||||||
|
|
||||||
//If its the main zone we need to visualize the Zone bounds displayed
|
//If its the main zone we need to visualize the Zone bounds displayed
|
||||||
if (Zones.Count > 0)
|
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)
|
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);
|
g.DrawRectangle(Pens.Red, newBounds);
|
||||||
}
|
}
|
||||||
foreach (Window w in Windows)
|
foreach (Window w in Windows)
|
||||||
@@ -155,7 +158,7 @@ namespace Test_Merge
|
|||||||
public virtual string ToJSON()
|
public virtual string ToJSON()
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
result += "\"" + "Zone" + "\":{" + Environment.NewLine;
|
result += "\"" + Name + "\":{" + Environment.NewLine;
|
||||||
result += "\t" + "\"x\":" + Bounds.X + "," + Environment.NewLine;
|
result += "\t" + "\"x\":" + Bounds.X + "," + Environment.NewLine;
|
||||||
result += "\t" + "\"y\":" + Bounds.Y + "," + Environment.NewLine;
|
result += "\t" + "\"y\":" + Bounds.Y + "," + Environment.NewLine;
|
||||||
result += "\t" + "\"width\":" + Bounds.Width + "," + Environment.NewLine;
|
result += "\t" + "\"width\":" + Bounds.Width + "," + Environment.NewLine;
|
||||||
|
|||||||
Reference in New Issue
Block a user