You can now also add windows and it all gets dump into a nice directory for each driver.
This commit is contained in:
Generated
+2
-1
@@ -108,9 +108,10 @@
|
||||
this.pbxWindow.Location = new System.Drawing.Point(12, 558);
|
||||
this.pbxWindow.Name = "pbxWindow";
|
||||
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.TabStop = false;
|
||||
this.pbxWindow.Click += new System.EventHandler(this.pbxWindow_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
|
||||
+46
-7
@@ -24,6 +24,8 @@ namespace OCR_tester
|
||||
|
||||
bool selectingZonePoints = false;
|
||||
bool selectingWindowPoints = false;
|
||||
|
||||
MainZone mainZone;
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -41,6 +43,7 @@ namespace OCR_tester
|
||||
SwitchCreateWindowButton();
|
||||
selectingZonePoints = true;
|
||||
zonePoints = new Point[] { new Point(-1, -1), new Point(-1, -1) };
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -67,11 +70,11 @@ namespace OCR_tester
|
||||
}
|
||||
private void UpdateCreateWindowButton()
|
||||
{
|
||||
btnCreateWindow.Text = "Points remaining : " + ZonePointsRemaining();
|
||||
btnCreateWindow.Text = "Points remaining : " + PointsRemaining(windowPoints);
|
||||
}
|
||||
private void UpdateCreateZoneButton()
|
||||
{
|
||||
btnCreateZone.Text = "Points remaining : " + ZonePointsRemaining();
|
||||
btnCreateZone.Text = "Points remaining : " + PointsRemaining(zonePoints);
|
||||
}
|
||||
private void btnCreateZone_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -81,10 +84,10 @@ namespace OCR_tester
|
||||
{
|
||||
SwitchCreateWindowButton();
|
||||
}
|
||||
private int ZonePointsRemaining()
|
||||
private int PointsRemaining(Point[] points)
|
||||
{
|
||||
int remaining = 0;
|
||||
foreach (Point p in zonePoints)
|
||||
foreach (Point p in points)
|
||||
{
|
||||
if (p.X == -1 && p.Y == -1)
|
||||
remaining++;
|
||||
@@ -100,7 +103,7 @@ namespace OCR_tester
|
||||
float yOffset = (float)pbxInput.Image.Height / (float)pbxInput.Height;
|
||||
if (selectingZonePoints)
|
||||
{
|
||||
int remaining = ZonePointsRemaining();
|
||||
int remaining = PointsRemaining(zonePoints);
|
||||
int index = (zonePoints.Length) - remaining;
|
||||
zonePoints[index] = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset));
|
||||
remaining -= 1;
|
||||
@@ -109,9 +112,9 @@ namespace OCR_tester
|
||||
{
|
||||
Image fullImage = pbxInput.Image;
|
||||
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();
|
||||
|
||||
pbxWindow.Image = mainZone.Zones[0].ZoneImage;
|
||||
SwitchCreateZoneButton();
|
||||
}
|
||||
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)
|
||||
{
|
||||
reload();
|
||||
|
||||
+16
-2
@@ -72,16 +72,30 @@ namespace OCR_tester
|
||||
Zones.Add(new Zone(ZoneImage, windowRectangle));
|
||||
}
|
||||
}
|
||||
public Bitmap Draw()
|
||||
public override Bitmap Draw()
|
||||
{
|
||||
Bitmap image = ZoneImage;
|
||||
Graphics g = Graphics.FromImage(image);
|
||||
string imgDumbFil = @"C:\Users\Moi\Desktop\imgDump\";
|
||||
|
||||
int count = 0;
|
||||
foreach (Zone z in Zones)
|
||||
{
|
||||
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++;
|
||||
}
|
||||
image.Save(@"C:\Users\Moi\Desktop\imgDump\test.png");
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace OCR_tester
|
||||
private Bitmap FullImage;
|
||||
|
||||
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");
|
||||
|
||||
|
||||
+21
-9
@@ -10,10 +10,12 @@ namespace OCR_tester
|
||||
public class Zone
|
||||
{
|
||||
protected Bitmap FullImage;
|
||||
protected List<Zone> Zones;
|
||||
protected List<Window> Windows;
|
||||
private List<Zone> _zones;
|
||||
private List<Window> _windows;
|
||||
|
||||
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 Bitmap ZoneImage
|
||||
@@ -43,15 +45,15 @@ namespace OCR_tester
|
||||
Zones = new List<Zone>();
|
||||
Windows = new List<Window>();
|
||||
}
|
||||
private void AddZone(Rectangle bounds)
|
||||
{
|
||||
if(Fits(bounds))
|
||||
Zones.Add(new Zone(ZoneImage,bounds));
|
||||
}
|
||||
private void AddWindow(Rectangle bounds)
|
||||
public void AddZone(Rectangle 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>
|
||||
/// Checks if the given Rectangle fits in the current zone
|
||||
@@ -69,5 +71,15 @@ namespace OCR_tester
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user