Now the OCR applies and only crashes sometimes. But its complete trash and the images cant change for whatever reason

This commit is contained in:
2023-05-10 16:00:01 +02:00
parent df9231aed6
commit 2c1340780e
7 changed files with 138 additions and 18 deletions
+1 -1
View File
@@ -273,7 +273,7 @@ namespace Test_Merge
try try
{ {
//Screenshot scrsht = ((ITakesScreenshot)Driver).GetScreenshot(); //Screenshot scrsht = ((ITakesScreenshot)Driver).GetScreenshot();
//profileriver.SetPreference("layout.css.devPixelsPerPx", "1.0"); //profileriver.SetPreferencC:\Users\Moi\source\repos\Test_Merge\README.mde("layout.css.devPixelsPerPx", "1.0");
//Screenshot scrsht = Driver.GetFullPageScreenshot(); //Screenshot scrsht = Driver.GetFullPageScreenshot();
Screenshot scrsht = Driver.GetScreenshot(); Screenshot scrsht = Driver.GetScreenshot();
+26
View File
@@ -29,6 +29,8 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.btnSettings = new System.Windows.Forms.Button(); this.btnSettings = new System.Windows.Forms.Button();
this.tbxResult = new System.Windows.Forms.TextBox();
this.btnUpdate = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// btnSettings // btnSettings
@@ -41,21 +43,45 @@
this.btnSettings.UseVisualStyleBackColor = true; this.btnSettings.UseVisualStyleBackColor = true;
this.btnSettings.Click += new System.EventHandler(this.btnSettings_Click); this.btnSettings.Click += new System.EventHandler(this.btnSettings_Click);
// //
// tbxResult
//
this.tbxResult.Location = new System.Drawing.Point(12, 71);
this.tbxResult.Multiline = true;
this.tbxResult.Name = "tbxResult";
this.tbxResult.Size = new System.Drawing.Size(310, 249);
this.tbxResult.TabIndex = 1;
//
// btnUpdate
//
this.btnUpdate.Location = new System.Drawing.Point(120, 12);
this.btnUpdate.Name = "btnUpdate";
this.btnUpdate.Size = new System.Drawing.Size(102, 53);
this.btnUpdate.TabIndex = 2;
this.btnUpdate.Text = "Update";
this.btnUpdate.UseVisualStyleBackColor = true;
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.btnUpdate);
this.Controls.Add(this.tbxResult);
this.Controls.Add(this.btnSettings); this.Controls.Add(this.btnSettings);
this.Name = "Form1"; this.Name = "Form1";
this.Text = "Form1"; this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.Button btnSettings; private System.Windows.Forms.Button btnSettings;
private System.Windows.Forms.TextBox tbxResult;
private System.Windows.Forms.Button btnUpdate;
} }
} }
+30 -2
View File
@@ -11,17 +11,45 @@ using System.Windows.Forms;
namespace Test_Merge namespace Test_Merge
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
Reader Reader = null;
F1TVEmulator Emulator = null;
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
} }
public async void RefreshUI()
{
if(Emulator != null && Reader != null)
{
Bitmap screen = Emulator.Screenshot();
screen.Save("SCREEEEEEEEN.png");
Reader.ChangeImage(screen);
tbxResult.Text = await Reader.Decode(Reader.MainZones,Reader.Drivers,screen);
}
}
private void btnSettings_Click(object sender, EventArgs e) private void btnSettings_Click(object sender, EventArgs e)
{ {
Settings settingsForm = new Settings(); Settings settingsForm = new Settings();
settingsForm.ShowDialog(); settingsForm.ShowDialog();
MessageBox.Show(settingsForm.GrandPrixUrl + Environment.NewLine + settingsForm.GrandPrixName + Environment.NewLine + settingsForm.GrandPrixYear); MessageBox.Show(settingsForm.GrandPrixUrl + Environment.NewLine + settingsForm.GrandPrixName + Environment.NewLine + settingsForm.GrandPrixYear);
} }
private async void Form1_Load(object sender, EventArgs e)
{
string configFile = "./Presets/Clean_2023.json";
string gpUrl = "https://f1tv.formula1.com/detail/1000006688/2023-azerbaijan-grand-prix?action=play";
Emulator = new F1TVEmulator(gpUrl);
await Emulator.Start();
Reader = new Reader(configFile,Emulator.Screenshot(),true);
}
private void btnUpdate_Click(object sender, EventArgs e)
{
btnUpdate.Enabled = false;
RefreshUI();
btnUpdate.Enabled = true;
}
} }
} }
+4 -3
View File
@@ -48,14 +48,14 @@ namespace Test_Merge
{ {
case WindowType.LapTime: case WindowType.LapTime:
outputBitmap = Tresholding(outputBitmap, 185); outputBitmap = Tresholding(outputBitmap, 185);
outputBitmap = Resize(outputBitmap, 2); //outputBitmap = Resize(outputBitmap, 2);
outputBitmap = Dilatation(outputBitmap, 1); outputBitmap = Dilatation(outputBitmap, 1);
outputBitmap = Erode(outputBitmap, 1); outputBitmap = Erode(outputBitmap, 1);
break; break;
case WindowType.Text: case WindowType.Text:
outputBitmap = InvertColors(outputBitmap); outputBitmap = InvertColors(outputBitmap);
outputBitmap = Tresholding(outputBitmap, 165); outputBitmap = Tresholding(outputBitmap, 165);
outputBitmap = Resize(outputBitmap, 2); //outputBitmap = Resize(outputBitmap, 2);
outputBitmap = Dilatation(outputBitmap, 1); outputBitmap = Dilatation(outputBitmap, 1);
break; break;
case WindowType.Tyre: case WindowType.Tyre:
@@ -65,7 +65,8 @@ namespace Test_Merge
break; break;
default: default:
outputBitmap = Tresholding(outputBitmap, 165); outputBitmap = Tresholding(outputBitmap, 165);
outputBitmap = Resize(outputBitmap, 4); //outputBitmap = Resize(outputBitmap, 4);
outputBitmap = Resize(outputBitmap, 2);
outputBitmap = Erode(outputBitmap, 1); outputBitmap = Erode(outputBitmap, 1);
break; break;
} }
+16 -4
View File
@@ -34,7 +34,6 @@ namespace Test_Merge
{ {
List<Zone> mainZones = new List<Zone>(); List<Zone> mainZones = new List<Zone>();
Bitmap fullImage = image; Bitmap fullImage = image;
List<string> drivers;
Zone mainZone; Zone mainZone;
try try
@@ -56,7 +55,7 @@ namespace Test_Merge
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(image, MainRectangle,"Main"); mainZone = new Zone(fullImage, MainRectangle,"Main");
var zones = mainProperty.GetProperty("Zones"); var zones = mainProperty.GetProperty("Zones");
var driverZone = zones[0].GetProperty("DriverZone"); var driverZone = zones[0].GetProperty("DriverZone");
@@ -155,7 +154,7 @@ 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>a string representation of all the returns</returns> /// <returns>a string representation of all the returns</returns>
public async Task<string> Decode(List<Zone> mainZones,List<string> drivers) public async Task<string> Decode(List<Zone> mainZones,List<string> drivers, Bitmap imageToDecode)
{ {
string result = ""; string result = "";
List<DriverData> mainResults = new List<DriverData>(); List<DriverData> mainResults = new List<DriverData>();
@@ -167,9 +166,14 @@ namespace Test_Merge
{ {
case 0: case 0:
//Main Zone //Main Zone
int driverID = 0;
foreach (Zone z in mainZones[mainZoneId].Zones) foreach (Zone z in mainZones[mainZoneId].Zones)
{ {
mainResults.Add(await z.Decode(Drivers)); driverID++;
if (driverID == 9)
Console.WriteLine("AAAAA");
z.ZoneImage.Save("PUTAIN_DE_PILOTE_N"+driverID+".png");
mainResults.Add(await z.Decode(drivers));
} }
break; break;
//Next there could be a Title Zone and TrackInfoZone //Next there could be a Title Zone and TrackInfoZone
@@ -185,6 +189,14 @@ namespace Test_Merge
return result; return result;
} }
public void ChangeImage(Bitmap Image)
{
foreach (Zone BigZone in MainZones)
{
BigZone.Image = Image;
}
}
/// <summary> /// <summary>
/// Method that can be used to convert an amount of miliseconds into a more readable human form /// Method that can be used to convert an amount of miliseconds into a more readable human form
/// </summary> /// </summary>
+31 -8
View File
@@ -161,15 +161,38 @@ namespace Test_Merge
//ss:ms //ss:ms
result = (Convert.ToInt32(rawNumbers[0]) * 1000) + Convert.ToInt32(rawNumbers[1]); result = (Convert.ToInt32(rawNumbers[0]) * 1000) + Convert.ToInt32(rawNumbers[1]);
if (result > 999999) if (result > (60000 + 999))
{ {
//We know that we have way too much seconds to make a minut if (windowType == OcrImage.WindowType.LapTime)
//Its usually because the ":" have been interpreted as a number {
int minuts = (int)(rawNumbers[0][0] - '0'); result = 0;
// rawNumbers[0][1] should contain the : that has been mistaken if (rawNumbers[0].Length == 4)
int seconds = Convert.ToInt32(rawNumbers[0][2].ToString() + rawNumbers[0][3].ToString()); {
int ms = Convert.ToInt32(rawNumbers[1]); result += Convert.ToInt32(rawNumbers[0][0]) * 60000;
result = (Convert.ToInt32(minuts) * 1000 * 60) + (Convert.ToInt32(seconds) * 1000) + Convert.ToInt32(ms); result += Convert.ToInt32(rawNumbers[0][2].ToString() + rawNumbers[0][3].ToString()) * 1000;
result += Convert.ToInt32(rawNumbers[1]);
}
else
{
//Fuck it
result = 0;
}
}
if (windowType == OcrImage.WindowType.Sector)
{
int seconds = 0;
if (rawNumbers[0].Length == 3)
{
//We have one char that we need to delete
//For no apparent reason im going to delete the first
seconds = Convert.ToInt32(rawNumbers[0][1].ToString() + rawNumbers[0][2].ToString());
}
if (rawNumbers[0].Length == 2) {
seconds = Convert.ToInt32(rawNumbers[0][0].ToString() + rawNumbers[0][1].ToString());
}
int ms = Convert.ToInt32(rawNumbers[1][0].ToString() + rawNumbers[1][1].ToString() + rawNumbers[1][2].ToString());
result = seconds * 1000 + ms;
}
} }
} }
else else
+30
View File
@@ -88,6 +88,7 @@ namespace Test_Merge
/// <returns>A driver data object that contains all the infos about a driver</returns> /// <returns>A driver data object that contains all the infos about a driver</returns>
public virtual async Task<DriverData> Decode(List<string> driverList) public virtual async Task<DriverData> Decode(List<string> driverList)
{ {
/*
int sectorCount = 0; int sectorCount = 0;
DriverData result = new DriverData(); DriverData result = new DriverData();
Parallel.ForEach(Windows, async w => Parallel.ForEach(Windows, async w =>
@@ -116,6 +117,35 @@ namespace Test_Merge
if (w is DriverTyresWindow) if (w is DriverTyresWindow)
result.CurrentTyre = (Tyre)await (w as DriverTyresWindow).DecodePng(); result.CurrentTyre = (Tyre)await (w as DriverTyresWindow).DecodePng();
}); });
*/
int sectorCount = 0;
DriverData result = new DriverData();
foreach(Window w in Windows)
{
// A switch would be prettier but I dont think its supported in this C# version
if (w is DriverNameWindow)
result.Name = (string)await (w as DriverNameWindow).DecodePng(driverList);
if (w is DriverDrsWindow)
result.DRS = (bool)await (w as DriverDrsWindow).DecodePng();
if (w is DriverGapToLeaderWindow)
result.GapToLeader = (int)await (w as DriverGapToLeaderWindow).DecodePng();
if (w is DriverLapTimeWindow)
result.LapTime = (int)await (w as DriverLapTimeWindow).DecodePng();
if (w is DriverPositionWindow)
result.Position = (int)await (w as DriverPositionWindow).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; return result;
} }
public virtual Bitmap Draw() public virtual Bitmap Draw()