You can now also add windows and it all gets dump into a nice directory for each driver.

This commit is contained in:
2023-03-31 15:24:03 +02:00
parent d60de1a0c0
commit 5ec9656b03
5 changed files with 86 additions and 20 deletions
+2 -1
View File
@@ -108,9 +108,10 @@
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(960, 42);
this.pbxWindow.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; 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);
// //
// Form1 // Form1
// //
+46 -7
View File
@@ -24,6 +24,8 @@ namespace OCR_tester
bool selectingZonePoints = false; bool selectingZonePoints = false;
bool selectingWindowPoints = false; bool selectingWindowPoints = false;
MainZone mainZone;
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
@@ -41,6 +43,7 @@ namespace OCR_tester
SwitchCreateWindowButton(); SwitchCreateWindowButton();
selectingZonePoints = true; selectingZonePoints = true;
zonePoints = new Point[] { new Point(-1, -1), new Point(-1, -1) }; zonePoints = new Point[] { new Point(-1, -1), new Point(-1, -1) };
} }
else else
{ {
@@ -67,11 +70,11 @@ namespace OCR_tester
} }
private void UpdateCreateWindowButton() private void UpdateCreateWindowButton()
{ {
btnCreateWindow.Text = "Points remaining : " + ZonePointsRemaining(); btnCreateWindow.Text = "Points remaining : " + PointsRemaining(windowPoints);
} }
private void UpdateCreateZoneButton() private void UpdateCreateZoneButton()
{ {
btnCreateZone.Text = "Points remaining : " + ZonePointsRemaining(); btnCreateZone.Text = "Points remaining : " + PointsRemaining(zonePoints);
} }
private void btnCreateZone_Click(object sender, EventArgs e) private void btnCreateZone_Click(object sender, EventArgs e)
{ {
@@ -81,10 +84,10 @@ namespace OCR_tester
{ {
SwitchCreateWindowButton(); SwitchCreateWindowButton();
} }
private int ZonePointsRemaining() private int PointsRemaining(Point[] points)
{ {
int remaining = 0; int remaining = 0;
foreach (Point p in zonePoints) foreach (Point p in points)
{ {
if (p.X == -1 && p.Y == -1) if (p.X == -1 && p.Y == -1)
remaining++; remaining++;
@@ -100,7 +103,7 @@ namespace OCR_tester
float yOffset = (float)pbxInput.Image.Height / (float)pbxInput.Height; float yOffset = (float)pbxInput.Image.Height / (float)pbxInput.Height;
if (selectingZonePoints) if (selectingZonePoints)
{ {
int remaining = ZonePointsRemaining(); int remaining = PointsRemaining(zonePoints);
int index = (zonePoints.Length) - remaining; int index = (zonePoints.Length) - remaining;
zonePoints[index] = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset)); zonePoints[index] = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset));
remaining -= 1; remaining -= 1;
@@ -109,9 +112,9 @@ namespace OCR_tester
{ {
Image fullImage = pbxInput.Image; Image fullImage = pbxInput.Image;
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 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;
SwitchCreateZoneButton(); SwitchCreateZoneButton();
} }
else else
@@ -120,7 +123,43 @@ namespace OCR_tester
} }
} }
} }
private void pbxWindow_Click(object sender, EventArgs e)
{
if (mainZone != null)
{
Point coordinates = pbxWindow.PointToClient(new Point(MousePosition.X, MousePosition.Y));
float xOffset = (float)pbxWindow.Image.Width / (float)pbxWindow.Width;
float yOffset = (float)pbxWindow.Image.Height / (float)pbxWindow.Height;
if (selectingWindowPoints)
{
int remaining = PointsRemaining(windowPoints);
int index = (windowPoints.Length) - remaining;
windowPoints[index] = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset));
remaining -= 1;
if (remaining == 0)
{
Image fullImage = pbxWindow.Image;
Point position = windowPoints[0];
Size newSize = new Size(windowPoints[1].X - windowPoints[0].X, windowPoints[1].Y - windowPoints[0].Y);
foreach (Zone z in mainZone.Zones)
{
z.AddWindow(new Rectangle(position,newSize));
}
pbxInput.Image = mainZone.Draw();
pbxWindow.Image = mainZone.Zones[0].Draw();
SwitchCreateWindowButton();
}
else
{
UpdateCreateWindowButton();
}
}
}
}
private void btnDeleteZone_Click(object sender, EventArgs e) private void btnDeleteZone_Click(object sender, EventArgs e)
{ {
reload(); reload();
+16 -2
View File
@@ -72,16 +72,30 @@ namespace OCR_tester
Zones.Add(new Zone(ZoneImage, windowRectangle)); Zones.Add(new Zone(ZoneImage, windowRectangle));
} }
} }
public Bitmap Draw() public override Bitmap Draw()
{ {
Bitmap image = ZoneImage; Bitmap image = ZoneImage;
Graphics g = Graphics.FromImage(image); Graphics g = Graphics.FromImage(image);
string imgDumbFil = @"C:\Users\Moi\Desktop\imgDump\";
int count = 0; int count = 0;
foreach (Zone z in Zones) foreach (Zone z in Zones)
{ {
g.DrawRectangle(Pens.Red,z.Bounds); g.DrawRectangle(Pens.Red,z.Bounds);
z.ZoneImage.Save(@"C:\Users\Moi\Desktop\imgDump\"+"driver"+count+".png"); string dir = imgDumbFil + "driver" + count + @"\";
if (Directory.Exists(dir))
Directory.Delete(dir, true);
Directory.CreateDirectory(dir);
z.ZoneImage.Save(Path.Combine(dir,("driver"+count+".png")));
int count2 = 0;
foreach (Window w in z.Windows)
{
g.DrawRectangle(Pens.Blue,w.Bounds);
w.WindowImage.Save(dir+"data"+count2+".png");
count2++;
}
count++; count++;
} }
image.Save(@"C:\Users\Moi\Desktop\imgDump\test.png"); image.Save(@"C:\Users\Moi\Desktop\imgDump\test.png");
+1 -1
View File
@@ -13,7 +13,7 @@ namespace OCR_tester
private Bitmap FullImage; private Bitmap FullImage;
private Rectangle _bounds; private Rectangle _bounds;
public Rectangle Bounds { get => _bounds; private 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");
+21 -9
View File
@@ -10,10 +10,12 @@ namespace OCR_tester
public class Zone public class Zone
{ {
protected Bitmap FullImage; protected Bitmap FullImage;
protected List<Zone> Zones; private List<Zone> _zones;
protected List<Window> Windows; private List<Window> _windows;
protected Rectangle _bounds; protected Rectangle _bounds;
public List<Zone> Zones { get => _zones; protected set => _zones = value; }
public List<Window> Windows { get => _windows; protected set => _windows = value; }
public Rectangle Bounds { get => _bounds; private set => _bounds = value; } public Rectangle Bounds { get => _bounds; private set => _bounds = value; }
public Bitmap ZoneImage public Bitmap ZoneImage
@@ -43,15 +45,15 @@ namespace OCR_tester
Zones = new List<Zone>(); Zones = new List<Zone>();
Windows = new List<Window>(); Windows = new List<Window>();
} }
private void AddZone(Rectangle bounds) public void AddZone(Rectangle bounds)
{
if(Fits(bounds))
Zones.Add(new Zone(ZoneImage,bounds));
}
private void AddWindow(Rectangle bounds)
{ {
if (Fits(bounds)) if (Fits(bounds))
Windows.Add(new Window(ZoneImage,bounds)); Zones.Add(new Zone(ZoneImage, bounds));
}
public void AddWindow(Rectangle bounds)
{
if (Fits(bounds))
Windows.Add(new Window(ZoneImage, bounds));
} }
/// <summary> /// <summary>
/// Checks if the given Rectangle fits in the current zone /// Checks if the given Rectangle fits in the current zone
@@ -69,5 +71,15 @@ namespace OCR_tester
return true; return true;
} }
} }
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;
}
} }
} }