End of the day push. Does not compile
This commit is contained in:
@@ -6,3 +6,5 @@ you will need to take a couple of folders and files in the /bin/debug or /bin/re
|
||||
|
||||
You need to take the recoverCookiesCSV.py in ./Test_Merge and put it in the /bin/... folder
|
||||
Same for the all geckodriver-v0.xx.x-win32 folder
|
||||
|
||||
You also have to change the TESS_DATA_FOLDER constant in the Windows.cs file. A small one is included in the project files
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace Test_Merge
|
||||
{
|
||||
public class ConfigurationTool
|
||||
{
|
||||
private Zone mainZone;
|
||||
const int NUMBER_OF_DRIVERS = 20;
|
||||
const int NUMBER_OF_ZONES = 7;
|
||||
|
||||
public ConfigurationTool()
|
||||
{
|
||||
//empty for now
|
||||
}
|
||||
public void AddZones(List<Rectangle> rectangles)
|
||||
{
|
||||
foreach (Zone driverZone in mainZone.Zones)
|
||||
{
|
||||
Bitmap zoneImage = driverZone.ZoneImage;
|
||||
|
||||
for ()
|
||||
{
|
||||
//We need to add all the zone and the types
|
||||
|
||||
//if i== 1 => driverZone.Add(new DriverPositionWindow)
|
||||
|
||||
}
|
||||
foreach (Rectangle rectangle in rectangles) {
|
||||
driverZone.AddWindow(new Window());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void AutoCalibrate()
|
||||
{
|
||||
List<Rectangle> detectedText = new List<Rectangle>();
|
||||
List<Zone> zones = new List<Zone>();
|
||||
|
||||
TesseractEngine engine = new TesseractEngine(Window.TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||
Image image = mainZone.ZoneImage;
|
||||
var tessImage = Pix.LoadFromMemory(Window.ImageToByte(image));
|
||||
|
||||
Page page = engine.Process(tessImage);
|
||||
using (var iter = page.GetIterator())
|
||||
{
|
||||
iter.Begin();
|
||||
do
|
||||
{
|
||||
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)
|
||||
{
|
||||
//Now we add a filter to only get the boxes in the right because they are much more reliable in size
|
||||
if (boundingBox.X1 > image.Width / 2)
|
||||
{
|
||||
//Now we check if an other square box has been found roughly in the same y axis
|
||||
bool match = false;
|
||||
//The tolerance is roughly half the size that a window will be
|
||||
int tolerance = (image.Height / NUMBER_OF_DRIVERS) / 2;
|
||||
|
||||
foreach (Rectangle rect in detectedText)
|
||||
{
|
||||
if (rect.Y > boundingBox.Y1 - tolerance && rect.Y < boundingBox.Y1 + tolerance)
|
||||
{
|
||||
//There already is a rectangle in this line
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
//if nothing matched we can add it
|
||||
if (!match)
|
||||
detectedText.Add(new Rectangle(boundingBox.X1, boundingBox.Y1, boundingBox.Width, boundingBox.Height));
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (iter.Next(PageIteratorLevel.Word));
|
||||
}
|
||||
foreach (Rectangle Rectangle in detectedText)
|
||||
{
|
||||
Rectangle windowRectangle;
|
||||
Size windowSize = new Size(image.Width, image.Height / NUMBER_OF_DRIVERS);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,9 +53,9 @@ namespace Test_Merge
|
||||
//Position
|
||||
result += "Position : " + Position + Environment.NewLine;
|
||||
//Gap
|
||||
result += "Gap to leader : " + Reader.ConvertMsToTime(GapToLeader) + Environment.NewLine;
|
||||
result += "Gap to leader : " + OCRDecoder.ConvertMsToTime(GapToLeader) + Environment.NewLine;
|
||||
//LapTime
|
||||
result += "Lap time : " + Reader.ConvertMsToTime(LapTime) + Environment.NewLine;
|
||||
result += "Lap time : " + OCRDecoder.ConvertMsToTime(LapTime) + Environment.NewLine;
|
||||
//DRS
|
||||
result += "DRS : " + DRS + Environment.NewLine;
|
||||
//Tyres
|
||||
@@ -63,11 +63,11 @@ namespace Test_Merge
|
||||
//Name
|
||||
result += "Driver name : " + Name + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 1 : " + Reader.ConvertMsToTime(Sector1) + Environment.NewLine;
|
||||
result += "Sector 1 : " + OCRDecoder.ConvertMsToTime(Sector1) + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 2 : " + Reader.ConvertMsToTime(Sector2) + Environment.NewLine;
|
||||
result += "Sector 2 : " + OCRDecoder.ConvertMsToTime(Sector2) + Environment.NewLine;
|
||||
//Sector 1
|
||||
result += "Sector 3 : " + Reader.ConvertMsToTime(Sector3) + Environment.NewLine;
|
||||
result += "Sector 3 : " + OCRDecoder.ConvertMsToTime(Sector3) + Environment.NewLine;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
|
||||
namespace Test_Merge
|
||||
{
|
||||
|
||||
@@ -143,9 +143,9 @@ namespace Test_Merge
|
||||
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 DriverSector1Window(zoneImg, new Rectangle(driverSector1Position, driverSector1Area)));
|
||||
newDriverZone.AddWindow(new DriverSector2Window(zoneImg, new Rectangle(driverSector2Position, driverSector2Area)));
|
||||
newDriverZone.AddWindow(new DriverSector3Window(zoneImg, new Rectangle(driverSector3Position, driverSector3Area)));
|
||||
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)));
|
||||
|
||||
MainZone.AddZone(newDriverZone);
|
||||
}//);
|
||||
|
||||
Binary file not shown.
@@ -86,7 +86,15 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConfigurationTool.cs" />
|
||||
<Compile Include="DriverData.cs" />
|
||||
<Compile Include="DriverDrsWindow.cs" />
|
||||
<Compile Include="DriverGapToLeaderWindow.cs" />
|
||||
<Compile Include="DriverLapTimeWindow.cs" />
|
||||
<Compile Include="DriverNameWindow.cs" />
|
||||
<Compile Include="DriverPositionWindow.cs" />
|
||||
<Compile Include="DriverSectorWindow.cs" />
|
||||
<Compile Include="DriverTyresWindow.cs" />
|
||||
<Compile Include="F1TVEmulator.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
@@ -293,5 +293,17 @@ namespace Test_Merge
|
||||
|
||||
return d[string1.Length, string2.Length];
|
||||
}
|
||||
public virtual string ToJSON()
|
||||
{
|
||||
string result = "";
|
||||
|
||||
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;
|
||||
result += "}";
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+93
-6
@@ -79,6 +79,7 @@ namespace Test_Merge
|
||||
/// <returns>A driver data object that contains all the infos about a driver</returns>
|
||||
public virtual async Task<DriverData> Decode(List<string> driverList)
|
||||
{
|
||||
int sectorCount = 0;
|
||||
DriverData result = new DriverData();
|
||||
Parallel.ForEach(Windows, async w =>
|
||||
{
|
||||
@@ -93,16 +94,102 @@ namespace Test_Merge
|
||||
result.LapTime = (int)await (w as DriverLapTimeWindow).DecodePng();
|
||||
if (w is DriverPositionWindow)
|
||||
result.Position = (int)await (w as DriverPositionWindow).DecodePng();
|
||||
if (w is DriverSector1Window)
|
||||
result.Sector1 = (int)await (w as DriverSector1Window).DecodePng();
|
||||
if (w is DriverSector2Window)
|
||||
result.Sector2 = (int)await (w as DriverSector2Window).DecodePng();
|
||||
if (w is DriverSector3Window)
|
||||
result.Sector3 = (int)await (w as DriverSector3Window).DecodePng();
|
||||
if (w is DriverSectorWindow)
|
||||
{
|
||||
sectorCount++;
|
||||
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();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
public virtual Bitmap Draw()
|
||||
{
|
||||
Image img = ZoneImage;
|
||||
Graphics g = Graphics.FromImage(img);
|
||||
foreach (Window w in Windows)
|
||||
{
|
||||
g.DrawRectangle(Pens.Blue, w.Bounds);
|
||||
}
|
||||
return (Bitmap)img;
|
||||
}
|
||||
public virtual string ToJSON()
|
||||
{
|
||||
string result = "";
|
||||
result += "\"" + "Zone" + "\":{" + Environment.NewLine;
|
||||
result += "\t" + "\"x\":" + Bounds.X + "," + Environment.NewLine;
|
||||
result += "\t" + "\"y\":" + Bounds.Y + "," + Environment.NewLine;
|
||||
result += "\t" + "\"width\":" + Bounds.Width + "," + Environment.NewLine;
|
||||
result += "\t" + "\"height\":" + Bounds.Height;
|
||||
|
||||
if (Windows.Count != 0)
|
||||
{
|
||||
result += "," + Environment.NewLine;
|
||||
|
||||
result += "\t" + "\"Windows\":[" + Environment.NewLine;
|
||||
result += "\t\t{" + Environment.NewLine;
|
||||
int Wcount = 0;
|
||||
foreach (Window w in Windows)
|
||||
{
|
||||
result += "\t\t" + w.ToJSON();
|
||||
Wcount++;
|
||||
if (Wcount != Windows.Count)
|
||||
result += ",";
|
||||
}
|
||||
result += "\t\t}" + Environment.NewLine;
|
||||
result += "\t" + "]" + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += Environment.NewLine;
|
||||
}
|
||||
if (Zones.Count != 0)
|
||||
{
|
||||
result += "," + Environment.NewLine;
|
||||
|
||||
result += "\t" + "\"Zones\":[" + Environment.NewLine;
|
||||
result += "\t\t{" + Environment.NewLine;
|
||||
int Zcount = 0;
|
||||
//foreach (Zone z in Zones)
|
||||
//{
|
||||
result += "\t\t" + Zones[0].ToJSON();
|
||||
Zcount++;
|
||||
if (Zcount != Zones.Count)
|
||||
//result += ",";
|
||||
//}
|
||||
result += "\t\t}" + Environment.NewLine;
|
||||
result += "\t" + "]" + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += Environment.NewLine;
|
||||
}
|
||||
|
||||
result += "}";
|
||||
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks if the given Rectangle fits in the current zone
|
||||
/// </summary>
|
||||
/// <param name="InputRectangle">The Rectangle you want to check the fittment</param>
|
||||
/// <returns></returns>
|
||||
protected bool Fits(Rectangle inputRectangle)
|
||||
{
|
||||
if (inputRectangle.X + inputRectangle.Width > Bounds.Width || inputRectangle.Y + inputRectangle.Height > Bounds.Height || inputRectangle.X < 0 || inputRectangle.Y < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user