Improved the old way of manually selecting windows, Added all the windows types and implemented them, You can now export to a bad json file
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverDrsWindow : Window
|
||||||
|
{
|
||||||
|
public DriverDrsWindow(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "Drs";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverGapToLeaderWindow : Window
|
||||||
|
{
|
||||||
|
|
||||||
|
public DriverGapToLeaderWindow(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "GapToLeader";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverLapTimeWindow : Window
|
||||||
|
{
|
||||||
|
public DriverLapTimeWindow(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "LapTime";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverNameWindow : Window
|
||||||
|
{
|
||||||
|
public DriverNameWindow(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "Name";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverPositionWindow : Window
|
||||||
|
{
|
||||||
|
public DriverPositionWindow(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "Position";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverSector1Window : Window
|
||||||
|
{
|
||||||
|
public DriverSector1Window(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "Sector1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverSector2Window : Window
|
||||||
|
{
|
||||||
|
public DriverSector2Window(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "Sector2";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverSector3Window : Window
|
||||||
|
{
|
||||||
|
public DriverSector3Window(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "Sector3";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
internal class DriverTyresWindow : Window
|
||||||
|
{
|
||||||
|
public DriverTyresWindow(Bitmap fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "Tyres";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OCR_tester
|
||||||
|
{
|
||||||
|
public class DriverZone : Zone
|
||||||
|
{
|
||||||
|
public DriverZone(Image fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
|
{
|
||||||
|
Name = "DriverZone";
|
||||||
|
}
|
||||||
|
public override void AddWindow(Rectangle bounds)
|
||||||
|
{
|
||||||
|
//base.AddWindow(bounds);
|
||||||
|
|
||||||
|
int count = Windows.Count();
|
||||||
|
Rectangle newBounds = new Rectangle(bounds.X, 0, bounds.Width, ZoneImage.Height);
|
||||||
|
switch (count)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverPositionWindow(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverGapToLeaderWindow(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverLapTimeWindow(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverDrsWindow(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverTyresWindow(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverNameWindow(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverSector1Window(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverSector2Window(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new DriverSector3Window(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (Fits(bounds))
|
||||||
|
{
|
||||||
|
Windows.Add(new Window(ZoneImage, newBounds));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+19
-6
@@ -36,6 +36,7 @@
|
|||||||
this.btnDeleteWindow = new System.Windows.Forms.Button();
|
this.btnDeleteWindow = new System.Windows.Forms.Button();
|
||||||
this.panel2 = new System.Windows.Forms.Panel();
|
this.panel2 = new System.Windows.Forms.Panel();
|
||||||
this.pbxWindow = new System.Windows.Forms.PictureBox();
|
this.pbxWindow = new System.Windows.Forms.PictureBox();
|
||||||
|
this.btnExport = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxInput)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxInput)).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxWindow)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxWindow)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@@ -64,12 +65,12 @@
|
|||||||
//
|
//
|
||||||
this.panel1.Location = new System.Drawing.Point(984, 118);
|
this.panel1.Location = new System.Drawing.Point(984, 118);
|
||||||
this.panel1.Name = "panel1";
|
this.panel1.Name = "panel1";
|
||||||
this.panel1.Size = new System.Drawing.Size(268, 154);
|
this.panel1.Size = new System.Drawing.Size(268, 100);
|
||||||
this.panel1.TabIndex = 4;
|
this.panel1.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// btnCreateWindow
|
// btnCreateWindow
|
||||||
//
|
//
|
||||||
this.btnCreateWindow.Location = new System.Drawing.Point(978, 292);
|
this.btnCreateWindow.Location = new System.Drawing.Point(978, 224);
|
||||||
this.btnCreateWindow.Name = "btnCreateWindow";
|
this.btnCreateWindow.Name = "btnCreateWindow";
|
||||||
this.btnCreateWindow.Size = new System.Drawing.Size(280, 47);
|
this.btnCreateWindow.Size = new System.Drawing.Size(280, 47);
|
||||||
this.btnCreateWindow.TabIndex = 5;
|
this.btnCreateWindow.TabIndex = 5;
|
||||||
@@ -89,7 +90,7 @@
|
|||||||
//
|
//
|
||||||
// btnDeleteWindow
|
// btnDeleteWindow
|
||||||
//
|
//
|
||||||
this.btnDeleteWindow.Location = new System.Drawing.Point(978, 345);
|
this.btnDeleteWindow.Location = new System.Drawing.Point(978, 277);
|
||||||
this.btnDeleteWindow.Name = "btnDeleteWindow";
|
this.btnDeleteWindow.Name = "btnDeleteWindow";
|
||||||
this.btnDeleteWindow.Size = new System.Drawing.Size(280, 47);
|
this.btnDeleteWindow.Size = new System.Drawing.Size(280, 47);
|
||||||
this.btnDeleteWindow.TabIndex = 7;
|
this.btnDeleteWindow.TabIndex = 7;
|
||||||
@@ -98,7 +99,7 @@
|
|||||||
//
|
//
|
||||||
// panel2
|
// panel2
|
||||||
//
|
//
|
||||||
this.panel2.Location = new System.Drawing.Point(984, 398);
|
this.panel2.Location = new System.Drawing.Point(984, 330);
|
||||||
this.panel2.Name = "panel2";
|
this.panel2.Name = "panel2";
|
||||||
this.panel2.Size = new System.Drawing.Size(268, 154);
|
this.panel2.Size = new System.Drawing.Size(268, 154);
|
||||||
this.panel2.TabIndex = 5;
|
this.panel2.TabIndex = 5;
|
||||||
@@ -107,17 +108,28 @@
|
|||||||
//
|
//
|
||||||
this.pbxWindow.Location = new System.Drawing.Point(12, 558);
|
this.pbxWindow.Location = new System.Drawing.Point(12, 558);
|
||||||
this.pbxWindow.Name = "pbxWindow";
|
this.pbxWindow.Name = "pbxWindow";
|
||||||
this.pbxWindow.Size = new System.Drawing.Size(960, 42);
|
this.pbxWindow.Size = new System.Drawing.Size(1240, 59);
|
||||||
this.pbxWindow.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
this.pbxWindow.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||||
this.pbxWindow.TabIndex = 8;
|
this.pbxWindow.TabIndex = 8;
|
||||||
this.pbxWindow.TabStop = false;
|
this.pbxWindow.TabStop = false;
|
||||||
this.pbxWindow.Click += new System.EventHandler(this.pbxWindow_Click);
|
this.pbxWindow.Click += new System.EventHandler(this.pbxWindow_Click);
|
||||||
//
|
//
|
||||||
|
// btnExport
|
||||||
|
//
|
||||||
|
this.btnExport.Location = new System.Drawing.Point(978, 490);
|
||||||
|
this.btnExport.Name = "btnExport";
|
||||||
|
this.btnExport.Size = new System.Drawing.Size(280, 62);
|
||||||
|
this.btnExport.TabIndex = 9;
|
||||||
|
this.btnExport.Text = "Export";
|
||||||
|
this.btnExport.UseVisualStyleBackColor = true;
|
||||||
|
this.btnExport.Click += new System.EventHandler(this.btnExport_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(1264, 612);
|
this.ClientSize = new System.Drawing.Size(1264, 623);
|
||||||
|
this.Controls.Add(this.btnExport);
|
||||||
this.Controls.Add(this.pbxWindow);
|
this.Controls.Add(this.pbxWindow);
|
||||||
this.Controls.Add(this.panel2);
|
this.Controls.Add(this.panel2);
|
||||||
this.Controls.Add(this.btnDeleteWindow);
|
this.Controls.Add(this.btnDeleteWindow);
|
||||||
@@ -144,6 +156,7 @@
|
|||||||
private System.Windows.Forms.Button btnDeleteWindow;
|
private System.Windows.Forms.Button btnDeleteWindow;
|
||||||
private System.Windows.Forms.Panel panel2;
|
private System.Windows.Forms.Panel panel2;
|
||||||
private System.Windows.Forms.PictureBox pbxWindow;
|
private System.Windows.Forms.PictureBox pbxWindow;
|
||||||
|
private System.Windows.Forms.Button btnExport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-2
@@ -114,7 +114,7 @@ namespace OCR_tester
|
|||||||
Size newSize = new Size(zonePoints[1].X - zonePoints[0].X, zonePoints[1].Y - zonePoints[0].Y);
|
Size newSize = new Size(zonePoints[1].X - zonePoints[0].X, zonePoints[1].Y - zonePoints[0].Y);
|
||||||
mainZone = new MainZone(fullImage, new Rectangle(zonePoints[0], newSize));
|
mainZone = new MainZone(fullImage, new Rectangle(zonePoints[0], newSize));
|
||||||
pbxInput.Image = mainZone.Draw();
|
pbxInput.Image = mainZone.Draw();
|
||||||
pbxWindow.Image = mainZone.Zones[0].ZoneImage;
|
pbxWindow.Image = mainZone.Zones[1].ZoneImage;
|
||||||
SwitchCreateZoneButton();
|
SwitchCreateZoneButton();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -150,7 +150,7 @@ namespace OCR_tester
|
|||||||
z.AddWindow(new Rectangle(position,newSize));
|
z.AddWindow(new Rectangle(position,newSize));
|
||||||
}
|
}
|
||||||
pbxInput.Image = mainZone.Draw();
|
pbxInput.Image = mainZone.Draw();
|
||||||
pbxWindow.Image = mainZone.Zones[0].Draw();
|
pbxWindow.Image = mainZone.Zones[1].Draw();
|
||||||
SwitchCreateWindowButton();
|
SwitchCreateWindowButton();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -164,5 +164,21 @@ namespace OCR_tester
|
|||||||
{
|
{
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnExport_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string path = @"C:\Users\Moi\Desktop\imgDump\";
|
||||||
|
string name = "Dump.json";
|
||||||
|
if (File.Exists(path + name))
|
||||||
|
{
|
||||||
|
File.Delete(path+name);
|
||||||
|
}
|
||||||
|
using (StreamWriter writer = new StreamWriter(path+name))
|
||||||
|
{
|
||||||
|
writer.WriteLine("{");
|
||||||
|
writer.WriteLine(mainZone.ToJSON());
|
||||||
|
writer.WriteLine("}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace OCR_tester
|
|||||||
public MainZone(Image fullImage, Rectangle bounds) : base(fullImage, bounds)
|
public MainZone(Image fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||||
{
|
{
|
||||||
AutoCalibrate();
|
AutoCalibrate();
|
||||||
|
Name = "Main";
|
||||||
}
|
}
|
||||||
public void AutoCalibrate()
|
public void AutoCalibrate()
|
||||||
{
|
{
|
||||||
@@ -69,7 +70,7 @@ namespace OCR_tester
|
|||||||
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);
|
||||||
|
|
||||||
Zones.Add(new Zone(ZoneImage, windowRectangle));
|
Zones.Add(new DriverZone(ZoneImage, windowRectangle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override Bitmap Draw()
|
public override Bitmap Draw()
|
||||||
@@ -92,8 +93,8 @@ namespace OCR_tester
|
|||||||
int count2 = 0;
|
int count2 = 0;
|
||||||
foreach (Window w in z.Windows)
|
foreach (Window w in z.Windows)
|
||||||
{
|
{
|
||||||
g.DrawRectangle(Pens.Blue,w.Bounds);
|
g.DrawRectangle(Pens.Blue,new Rectangle(w.Bounds.X,w.Bounds.Y + count * z.Bounds.Height,w.Bounds.Width,w.Bounds.Height));
|
||||||
w.WindowImage.Save(dir+"data"+count2+".png");
|
w.WindowImage.Save(dir+w.Name+".png");
|
||||||
count2++;
|
count2++;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|||||||
@@ -51,6 +51,16 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="DriverDrsWindow.cs" />
|
||||||
|
<Compile Include="DriverGapToLeaderWindow.cs" />
|
||||||
|
<Compile Include="DriverLapTimeWindow.cs" />
|
||||||
|
<Compile Include="DriverNameWindow.cs" />
|
||||||
|
<Compile Include="DriverPositionWindow.cs" />
|
||||||
|
<Compile Include="DriverSector1Window.cs" />
|
||||||
|
<Compile Include="DriverSector2Window.cs" />
|
||||||
|
<Compile Include="DriverSector3Window.cs" />
|
||||||
|
<Compile Include="DriverTyresWindow.cs" />
|
||||||
|
<Compile Include="DriverZone.cs" />
|
||||||
<Compile Include="Form1.cs">
|
<Compile Include="Form1.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
+17
-1
@@ -10,9 +10,12 @@ namespace OCR_tester
|
|||||||
{
|
{
|
||||||
public class Window
|
public class Window
|
||||||
{
|
{
|
||||||
private Bitmap FullImage;
|
protected Bitmap FullImage;
|
||||||
|
|
||||||
|
private string _name;
|
||||||
private Rectangle _bounds;
|
private Rectangle _bounds;
|
||||||
|
|
||||||
|
public string Name { get => _name; protected set => _name = value; }
|
||||||
public Rectangle Bounds { get => _bounds; protected set => _bounds = value; }
|
public Rectangle Bounds { get => _bounds; protected set => _bounds = value; }
|
||||||
|
|
||||||
public static DirectoryInfo tessDataFolder = new DirectoryInfo(@"C:\Users\Moi\Pictures\SeleniumScreens\TessData");
|
public static DirectoryInfo tessDataFolder = new DirectoryInfo(@"C:\Users\Moi\Pictures\SeleniumScreens\TessData");
|
||||||
@@ -27,6 +30,7 @@ namespace OCR_tester
|
|||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Window(Bitmap fullImage, Rectangle bounds)
|
public Window(Bitmap fullImage, Rectangle bounds)
|
||||||
{
|
{
|
||||||
FullImage = fullImage;
|
FullImage = fullImage;
|
||||||
@@ -44,5 +48,17 @@ namespace OCR_tester
|
|||||||
return stream.ToArray();
|
return stream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-1
@@ -12,6 +12,7 @@ namespace OCR_tester
|
|||||||
protected Bitmap FullImage;
|
protected Bitmap FullImage;
|
||||||
private List<Zone> _zones;
|
private List<Zone> _zones;
|
||||||
private List<Window> _windows;
|
private List<Window> _windows;
|
||||||
|
private string _name;
|
||||||
|
|
||||||
protected Rectangle _bounds;
|
protected Rectangle _bounds;
|
||||||
public List<Zone> Zones { get => _zones; protected set => _zones = value; }
|
public List<Zone> Zones { get => _zones; protected set => _zones = value; }
|
||||||
@@ -29,6 +30,8 @@ namespace OCR_tester
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get => _name; set => _name = value; }
|
||||||
|
|
||||||
public Zone(Image fullImage, Rectangle bounds)
|
public Zone(Image fullImage, Rectangle bounds)
|
||||||
{
|
{
|
||||||
FullImage = (Bitmap)fullImage;
|
FullImage = (Bitmap)fullImage;
|
||||||
@@ -50,7 +53,7 @@ namespace OCR_tester
|
|||||||
if (Fits(bounds))
|
if (Fits(bounds))
|
||||||
Zones.Add(new Zone(ZoneImage, bounds));
|
Zones.Add(new Zone(ZoneImage, bounds));
|
||||||
}
|
}
|
||||||
public void AddWindow(Rectangle bounds)
|
public virtual void AddWindow(Rectangle bounds)
|
||||||
{
|
{
|
||||||
if (Fits(bounds))
|
if (Fits(bounds))
|
||||||
Windows.Add(new Window(ZoneImage, bounds));
|
Windows.Add(new Window(ZoneImage, bounds));
|
||||||
@@ -81,5 +84,61 @@ namespace OCR_tester
|
|||||||
}
|
}
|
||||||
return (Bitmap)img;
|
return (Bitmap)img;
|
||||||
}
|
}
|
||||||
|
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 += "\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" + z.ToJSON();
|
||||||
|
Zcount++;
|
||||||
|
if (Zcount != Zones.Count)
|
||||||
|
result += ",";
|
||||||
|
}
|
||||||
|
result += "\t\t}" + Environment.NewLine;
|
||||||
|
result += "\t" + "]" + Environment.NewLine;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += Environment.NewLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += "}";
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user