Files
OCR_TEST/OCR_tester/Form1.cs
T

90 lines
3.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace OCR_tester
{
public partial class Form1 : Form
{
DirectoryInfo imagesFolder = new DirectoryInfo(@"C:\Users\Moi\Pictures\SeleniumScreens\DataSetHighRes");
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 DEFAULT_CREATEZONE_BUTTON_TEXT = "Create Zone";
Point[] zonePoints = new Point[2] { new Point(-1, -1), new Point(-1, -1) };
bool selectingZonePoints = false;
public Form1()
{
InitializeComponent();
pbxInput.Image = Image.FromFile(Path.Combine(imagesFolder.FullName, DEFAULT_IMAGE_NAME + "30.png"));
}
private void btnCreateZone_Click(object sender, EventArgs e)
{
if (selectingZonePoints)
{
btnCreateZone.Text = DEFAULT_CREATEZONE_BUTTON_TEXT;
selectingZonePoints = false;
}
else
{
selectingZonePoints = true;
zonePoints = new Point[2] { new Point(-1, -1), new Point(-1, -1) };
btnCreateZone.Text = "Points remaining : " + ZonePointsRemaining();
}
}
private int ZonePointsRemaining()
{
int remaining = 0;
foreach (Point p in zonePoints)
{
if (p.X == -1 && p.Y == -1)
remaining++;
}
return remaining;
}
private void pbxInput_Click(object sender, EventArgs e)
{
MouseEventArgs me = (MouseEventArgs)e;
//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 yOffset = (float)pbxInput.Image.Height / (float)pbxInput.Height;
if (selectingZonePoints)
{
int remaining = ZonePointsRemaining();
int index = (zonePoints.Length) - remaining;
zonePoints[index] = new Point(Convert.ToInt32((float)coordinates.X * xOffset),Convert.ToInt32((float)coordinates.Y * yOffset));
remaining -= 1;
btnCreateZone.Text = "Points remaining : " + remaining;
if (remaining == 0)
{
selectingZonePoints = false;
btnCreateZone.Text = DEFAULT_CREATEZONE_BUTTON_TEXT;
//CREATE MAIN ZONE
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);
MainZone mainZone = new MainZone(fullImage, new Rectangle(zonePoints[0], newSize));
pbxInput.Image = mainZone.Draw();
}
}
}
}
}