Cleaned up a little bit to make room for the windows
This commit is contained in:
Generated
+17
-1
@@ -35,7 +35,9 @@
|
|||||||
this.btnDeleteZone = new System.Windows.Forms.Button();
|
this.btnDeleteZone = new System.Windows.Forms.Button();
|
||||||
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();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxInput)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxInput)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pbxWindow)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// pbxInput
|
// pbxInput
|
||||||
@@ -73,6 +75,7 @@
|
|||||||
this.btnCreateWindow.TabIndex = 5;
|
this.btnCreateWindow.TabIndex = 5;
|
||||||
this.btnCreateWindow.Text = "Create Window";
|
this.btnCreateWindow.Text = "Create Window";
|
||||||
this.btnCreateWindow.UseVisualStyleBackColor = true;
|
this.btnCreateWindow.UseVisualStyleBackColor = true;
|
||||||
|
this.btnCreateWindow.Click += new System.EventHandler(this.btnCreateWindow_Click);
|
||||||
//
|
//
|
||||||
// btnDeleteZone
|
// btnDeleteZone
|
||||||
//
|
//
|
||||||
@@ -82,6 +85,7 @@
|
|||||||
this.btnDeleteZone.TabIndex = 6;
|
this.btnDeleteZone.TabIndex = 6;
|
||||||
this.btnDeleteZone.Text = "Delete Zone";
|
this.btnDeleteZone.Text = "Delete Zone";
|
||||||
this.btnDeleteZone.UseVisualStyleBackColor = true;
|
this.btnDeleteZone.UseVisualStyleBackColor = true;
|
||||||
|
this.btnDeleteZone.Click += new System.EventHandler(this.btnDeleteZone_Click);
|
||||||
//
|
//
|
||||||
// btnDeleteWindow
|
// btnDeleteWindow
|
||||||
//
|
//
|
||||||
@@ -99,11 +103,21 @@
|
|||||||
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;
|
||||||
//
|
//
|
||||||
|
// pbxWindow
|
||||||
|
//
|
||||||
|
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.TabIndex = 8;
|
||||||
|
this.pbxWindow.TabStop = false;
|
||||||
|
//
|
||||||
// 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, 558);
|
this.ClientSize = new System.Drawing.Size(1264, 612);
|
||||||
|
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);
|
||||||
this.Controls.Add(this.btnDeleteZone);
|
this.Controls.Add(this.btnDeleteZone);
|
||||||
@@ -114,6 +128,7 @@
|
|||||||
this.Name = "Form1";
|
this.Name = "Form1";
|
||||||
this.Text = "OCR tester";
|
this.Text = "OCR tester";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxInput)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxInput)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pbxWindow)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -127,6 +142,7 @@
|
|||||||
private System.Windows.Forms.Button btnDeleteZone;
|
private System.Windows.Forms.Button btnDeleteZone;
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+63
-23
@@ -17,28 +17,69 @@ namespace OCR_tester
|
|||||||
const string DEFAULT_IMAGE_NAME = "screen_"; //You will need to add a number and extension after it ex: screen_2.png
|
const string DEFAULT_IMAGE_NAME = "screen_"; //You will need to add a number and extension after it ex: screen_2.png
|
||||||
const string ENGLISH_TESSDATA_FILENAME = "eng.traineddata";
|
const string ENGLISH_TESSDATA_FILENAME = "eng.traineddata";
|
||||||
const string DEFAULT_CREATEZONE_BUTTON_TEXT = "Create Zone";
|
const string DEFAULT_CREATEZONE_BUTTON_TEXT = "Create Zone";
|
||||||
|
const string DEFAULT_CREATEWINDOW_BUTTON_TEXT = "Create Window";
|
||||||
|
|
||||||
|
Point[] zonePoints;
|
||||||
|
Point[] windowPoints;
|
||||||
|
|
||||||
Point[] zonePoints = new Point[2] { new Point(-1, -1), new Point(-1, -1) };
|
|
||||||
bool selectingZonePoints = false;
|
bool selectingZonePoints = false;
|
||||||
|
bool selectingWindowPoints = false;
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
private void reload()
|
||||||
|
{
|
||||||
pbxInput.Image = Image.FromFile(Path.Combine(imagesFolder.FullName, DEFAULT_IMAGE_NAME + "30.png"));
|
pbxInput.Image = Image.FromFile(Path.Combine(imagesFolder.FullName, DEFAULT_IMAGE_NAME + "30.png"));
|
||||||
}
|
}
|
||||||
|
private void SwitchCreateZoneButton()
|
||||||
private void btnCreateZone_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
if (selectingZonePoints)
|
if (!selectingWindowPoints)
|
||||||
{
|
{
|
||||||
btnCreateZone.Text = DEFAULT_CREATEZONE_BUTTON_TEXT;
|
if (selectingWindowPoints)
|
||||||
selectingZonePoints = false;
|
SwitchCreateWindowButton();
|
||||||
|
selectingZonePoints = true;
|
||||||
|
zonePoints = new Point[] { new Point(-1, -1), new Point(-1, -1) };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selectingZonePoints = true;
|
selectingZonePoints = false;
|
||||||
zonePoints = new Point[2] { new Point(-1, -1), new Point(-1, -1) };
|
|
||||||
btnCreateZone.Text = "Points remaining : " + ZonePointsRemaining();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateCreateZoneButton();
|
||||||
|
}
|
||||||
|
private void SwitchCreateWindowButton()
|
||||||
|
{
|
||||||
|
if (!selectingWindowPoints)
|
||||||
|
{
|
||||||
|
if (selectingZonePoints)
|
||||||
|
SwitchCreateZoneButton();
|
||||||
|
selectingWindowPoints = true;
|
||||||
|
windowPoints = new Point[] { new Point(-1, -1), new Point(-1, -1) };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selectingWindowPoints = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateCreateWindowButton();
|
||||||
|
}
|
||||||
|
private void UpdateCreateWindowButton()
|
||||||
|
{
|
||||||
|
btnCreateWindow.Text = "Points remaining : " + ZonePointsRemaining();
|
||||||
|
}
|
||||||
|
private void UpdateCreateZoneButton()
|
||||||
|
{
|
||||||
|
btnCreateZone.Text = "Points remaining : " + ZonePointsRemaining();
|
||||||
|
}
|
||||||
|
private void btnCreateZone_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SwitchCreateZoneButton();
|
||||||
|
}
|
||||||
|
private void btnCreateWindow_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SwitchCreateWindowButton();
|
||||||
}
|
}
|
||||||
private int ZonePointsRemaining()
|
private int ZonePointsRemaining()
|
||||||
{
|
{
|
||||||
@@ -53,11 +94,7 @@ namespace OCR_tester
|
|||||||
|
|
||||||
private void pbxInput_Click(object sender, EventArgs e)
|
private void pbxInput_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
MouseEventArgs me = (MouseEventArgs)e;
|
Point coordinates = pbxInput.PointToClient(new Point(MousePosition.X, MousePosition.Y));
|
||||||
//Point coordinates = new Point(Cursor.Location.X - pbxInput.Location.X,Cursor.Location.Y-pbxInput.Location.Y);
|
|
||||||
//Point coordinates = new Point(me.X,me.Y);
|
|
||||||
Point coordinates = pbxInput.PointToClient(new Point(MousePosition.X, MousePosition.Y));
|
|
||||||
//MessageBox.Show("Coordinates "+coordinates.X+":"+coordinates.Y);
|
|
||||||
|
|
||||||
float xOffset = (float)pbxInput.Image.Width / (float)pbxInput.Width;
|
float xOffset = (float)pbxInput.Image.Width / (float)pbxInput.Width;
|
||||||
float yOffset = (float)pbxInput.Image.Height / (float)pbxInput.Height;
|
float yOffset = (float)pbxInput.Image.Height / (float)pbxInput.Height;
|
||||||
@@ -65,25 +102,28 @@ namespace OCR_tester
|
|||||||
{
|
{
|
||||||
int remaining = ZonePointsRemaining();
|
int remaining = ZonePointsRemaining();
|
||||||
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;
|
||||||
btnCreateZone.Text = "Points remaining : " + remaining;
|
|
||||||
|
|
||||||
if (remaining == 0)
|
if (remaining == 0)
|
||||||
{
|
{
|
||||||
selectingZonePoints = false;
|
|
||||||
btnCreateZone.Text = DEFAULT_CREATEZONE_BUTTON_TEXT;
|
|
||||||
|
|
||||||
//CREATE MAIN ZONE
|
|
||||||
Image fullImage = pbxInput.Image;
|
Image fullImage = pbxInput.Image;
|
||||||
//13 186
|
|
||||||
//1920 960 HARD CODED
|
|
||||||
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 mainZone = new MainZone(fullImage, new Rectangle(zonePoints[0], newSize));
|
||||||
pbxInput.Image = mainZone.Draw();
|
pbxInput.Image = mainZone.Draw();
|
||||||
}
|
|
||||||
|
|
||||||
|
SwitchCreateZoneButton();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateCreateZoneButton();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnDeleteZone_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-18
@@ -20,7 +20,7 @@ namespace OCR_tester
|
|||||||
public void AutoCalibrate()
|
public void AutoCalibrate()
|
||||||
{
|
{
|
||||||
List<Rectangle> detectedText = new List<Rectangle>();
|
List<Rectangle> detectedText = new List<Rectangle>();
|
||||||
Windows = new List<Window>();
|
Zones = new List<Zone>();
|
||||||
|
|
||||||
TesseractEngine engine = new TesseractEngine(Window.tessDataFolder.FullName, "eng", EngineMode.Default);
|
TesseractEngine engine = new TesseractEngine(Window.tessDataFolder.FullName, "eng", EngineMode.Default);
|
||||||
Image image = ZoneImage;
|
Image image = ZoneImage;
|
||||||
@@ -61,23 +61,15 @@ namespace OCR_tester
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (iter.Next(PageIteratorLevel.Word));
|
} 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);
|
|
||||||
|
|
||||||
Windows.Add(new Window(ZoneImage,windowRectangle));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
foreach (Rectangle Rectangle in detectedText)
|
||||||
//Now that we have all the detected text we can try to split the zone
|
|
||||||
|
|
||||||
foreach (Rectangle rect in detectedText)
|
|
||||||
{
|
{
|
||||||
//To do
|
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);
|
||||||
|
|
||||||
|
Zones.Add(new Zone(ZoneImage, windowRectangle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Bitmap Draw()
|
public Bitmap Draw()
|
||||||
@@ -85,9 +77,12 @@ namespace OCR_tester
|
|||||||
Bitmap image = ZoneImage;
|
Bitmap image = ZoneImage;
|
||||||
Graphics g = Graphics.FromImage(image);
|
Graphics g = Graphics.FromImage(image);
|
||||||
|
|
||||||
foreach (Window w in Windows)
|
int count = 0;
|
||||||
|
foreach (Zone z in Zones)
|
||||||
{
|
{
|
||||||
g.DrawRectangle(Pens.Red,w.Bounds);
|
g.DrawRectangle(Pens.Red,z.Bounds);
|
||||||
|
z.ZoneImage.Save(@"C:\Users\Moi\Desktop\imgDump\"+"driver"+count+".png");
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
image.Save(@"C:\Users\Moi\Desktop\imgDump\test.png");
|
image.Save(@"C:\Users\Moi\Desktop\imgDump\test.png");
|
||||||
return image;
|
return image;
|
||||||
|
|||||||
Reference in New Issue
Block a user