Cleaned Zone.cs

This commit is contained in:
2023-04-25 15:22:11 +02:00
parent 32b20ff317
commit 57f19a1438
+25 -3
View File
@@ -1,4 +1,10 @@
using System; /// Author : Maxime Rohmer
/// Date : 25/04/2023
/// File : Zone.cs
/// Brief : Parent for futur zones and the that contains all the usefull methods for any zone
/// Version : 0.1
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -18,6 +24,7 @@ namespace OCR_Decode
{ {
get get
{ {
//This little trickery lets you have the image that the zone sees
Bitmap sample = new Bitmap(Bounds.Width, Bounds.Height); Bitmap sample = new Bitmap(Bounds.Width, Bounds.Height);
Graphics g = Graphics.FromImage(sample); Graphics g = Graphics.FromImage(sample);
g.DrawImage(Image, new Rectangle(0, 0, sample.Width, sample.Height), Bounds, GraphicsUnit.Pixel); g.DrawImage(Image, new Rectangle(0, 0, sample.Width, sample.Height), Bounds, GraphicsUnit.Pixel);
@@ -29,6 +36,7 @@ namespace OCR_Decode
get { return _image; } get { return _image; }
set set
{ {
//It automatically sets the image for the contained windows and zones
_image = Image; _image = Image;
foreach (Window w in Windows) foreach (Window w in Windows)
{ {
@@ -54,21 +62,35 @@ namespace OCR_Decode
_image = image; _image = image;
Bounds = bounds; Bounds = bounds;
} }
/// <summary>
/// Adds a zone to the list of zones
/// </summary>
/// <param name="zone">The zone you want to add</param>
public virtual void AddZone(Zone zone) public virtual void AddZone(Zone zone)
{ {
Zones.Add(zone); Zones.Add(zone);
} }
/// <summary>
/// Add a window to the list of windows
/// </summary>
/// <param name="window">the window you want to add</param>
public virtual void AddWindow(Window window) public virtual void AddWindow(Window window)
{ {
Windows.Add(window); Windows.Add(window);
} }
public virtual async Task<DriverData> Decode(List<string> drivers) /// <summary>
/// Calls all the zones and windows to do OCR and to give back the results so we can send them to the model
/// </summary>
/// <param name="driverList">A list of all the driver in the race to help with text recognition</param>
/// <returns>A driver data object that contains all the infos about a driver</returns>
public virtual async Task<DriverData> Decode(List<string> driverList)
{ {
DriverData result = new DriverData(); DriverData result = new DriverData();
Parallel.ForEach(Windows,async w => Parallel.ForEach(Windows,async w =>
{ {
// A switch would be prettier but I dont think its supported in this C# version
if (w is DriverNameWindow) if (w is DriverNameWindow)
result.Name = (string)await (w as DriverNameWindow).DecodePng(drivers); result.Name = (string)await (w as DriverNameWindow).DecodePng(driverList);
if (w is DriverDrsWindow) if (w is DriverDrsWindow)
result.DRS = (bool)await (w as DriverDrsWindow).DecodePng(); result.DRS = (bool)await (w as DriverDrsWindow).DecodePng();
if (w is DriverGapToLeaderWindow) if (w is DriverGapToLeaderWindow)