From 7292b136de5ce814de6a1a8f8867dba8aac44911 Mon Sep 17 00:00:00 2001 From: maxluli Date: Fri, 31 Mar 2023 12:36:40 +0200 Subject: [PATCH] First time I found helpfull to push this to git --- .gitignore | 402 ++++++++++++++++++++ OCR_tester.sln | 25 ++ OCR_tester/App.config | 6 + OCR_tester/Form1.Designer.cs | 132 +++++++ OCR_tester/Form1.cs | 89 +++++ OCR_tester/Form1.resx | 120 ++++++ OCR_tester/MainZone.cs | 61 +++ OCR_tester/OCR_tester.csproj | 99 +++++ OCR_tester/Program.cs | 22 ++ OCR_tester/Properties/AssemblyInfo.cs | 36 ++ OCR_tester/Properties/Resources.Designer.cs | 71 ++++ OCR_tester/Properties/Resources.resx | 117 ++++++ OCR_tester/Properties/Settings.Designer.cs | 30 ++ OCR_tester/Properties/Settings.settings | 7 + OCR_tester/Window.cs | 48 +++ OCR_tester/Zone.cs | 73 ++++ OCR_tester/packages.config | 4 + ReadMe.md | 3 + 18 files changed, 1345 insertions(+) create mode 100644 .gitignore create mode 100644 OCR_tester.sln create mode 100644 OCR_tester/App.config create mode 100644 OCR_tester/Form1.Designer.cs create mode 100644 OCR_tester/Form1.cs create mode 100644 OCR_tester/Form1.resx create mode 100644 OCR_tester/MainZone.cs create mode 100644 OCR_tester/OCR_tester.csproj create mode 100644 OCR_tester/Program.cs create mode 100644 OCR_tester/Properties/AssemblyInfo.cs create mode 100644 OCR_tester/Properties/Resources.Designer.cs create mode 100644 OCR_tester/Properties/Resources.resx create mode 100644 OCR_tester/Properties/Settings.Designer.cs create mode 100644 OCR_tester/Properties/Settings.settings create mode 100644 OCR_tester/Window.cs create mode 100644 OCR_tester/Zone.cs create mode 100644 OCR_tester/packages.config create mode 100644 ReadMe.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4507fc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,402 @@ +# Created by https://www.toptal.com/developers/gitignore/api/csharp +# Edit at https://www.toptal.com/developers/gitignore?templates=csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +# End of https://www.toptal.com/developers/gitignore/api/csharp \ No newline at end of file diff --git a/OCR_tester.sln b/OCR_tester.sln new file mode 100644 index 0000000..28aebb6 --- /dev/null +++ b/OCR_tester.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OCR_tester", "OCR_tester\OCR_tester.csproj", "{DDADF99C-AA21-4470-9AA4-E5C6E938D0B2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DDADF99C-AA21-4470-9AA4-E5C6E938D0B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DDADF99C-AA21-4470-9AA4-E5C6E938D0B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDADF99C-AA21-4470-9AA4-E5C6E938D0B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DDADF99C-AA21-4470-9AA4-E5C6E938D0B2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {82C5CE4A-B016-4EFC-8E88-89A7BAC2B45A} + EndGlobalSection +EndGlobal diff --git a/OCR_tester/App.config b/OCR_tester/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/OCR_tester/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OCR_tester/Form1.Designer.cs b/OCR_tester/Form1.Designer.cs new file mode 100644 index 0000000..3f2d353 --- /dev/null +++ b/OCR_tester/Form1.Designer.cs @@ -0,0 +1,132 @@ +namespace OCR_tester +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pbxInput = new System.Windows.Forms.PictureBox(); + this.btnCreateZone = new System.Windows.Forms.Button(); + this.panel1 = new System.Windows.Forms.Panel(); + this.btnCreateWindow = new System.Windows.Forms.Button(); + this.btnDeleteZone = new System.Windows.Forms.Button(); + this.btnDeleteWindow = new System.Windows.Forms.Button(); + this.panel2 = new System.Windows.Forms.Panel(); + ((System.ComponentModel.ISupportInitialize)(this.pbxInput)).BeginInit(); + this.SuspendLayout(); + // + // pbxInput + // + this.pbxInput.Location = new System.Drawing.Point(12, 12); + this.pbxInput.Name = "pbxInput"; + this.pbxInput.Size = new System.Drawing.Size(960, 540); + this.pbxInput.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pbxInput.TabIndex = 0; + this.pbxInput.TabStop = false; + this.pbxInput.Click += new System.EventHandler(this.pbxInput_Click); + // + // btnCreateZone + // + this.btnCreateZone.Location = new System.Drawing.Point(978, 12); + this.btnCreateZone.Name = "btnCreateZone"; + this.btnCreateZone.Size = new System.Drawing.Size(280, 47); + this.btnCreateZone.TabIndex = 3; + this.btnCreateZone.Text = "Create Zone"; + this.btnCreateZone.UseVisualStyleBackColor = true; + this.btnCreateZone.Click += new System.EventHandler(this.btnCreateZone_Click); + // + // panel1 + // + this.panel1.Location = new System.Drawing.Point(984, 118); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(268, 154); + this.panel1.TabIndex = 4; + // + // btnCreateWindow + // + this.btnCreateWindow.Location = new System.Drawing.Point(978, 292); + this.btnCreateWindow.Name = "btnCreateWindow"; + this.btnCreateWindow.Size = new System.Drawing.Size(280, 47); + this.btnCreateWindow.TabIndex = 5; + this.btnCreateWindow.Text = "Create Window"; + this.btnCreateWindow.UseVisualStyleBackColor = true; + // + // btnDeleteZone + // + this.btnDeleteZone.Location = new System.Drawing.Point(978, 65); + this.btnDeleteZone.Name = "btnDeleteZone"; + this.btnDeleteZone.Size = new System.Drawing.Size(280, 47); + this.btnDeleteZone.TabIndex = 6; + this.btnDeleteZone.Text = "Delete Zone"; + this.btnDeleteZone.UseVisualStyleBackColor = true; + // + // btnDeleteWindow + // + this.btnDeleteWindow.Location = new System.Drawing.Point(978, 345); + this.btnDeleteWindow.Name = "btnDeleteWindow"; + this.btnDeleteWindow.Size = new System.Drawing.Size(280, 47); + this.btnDeleteWindow.TabIndex = 7; + this.btnDeleteWindow.Text = "Delete Window"; + this.btnDeleteWindow.UseVisualStyleBackColor = true; + // + // panel2 + // + this.panel2.Location = new System.Drawing.Point(984, 398); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(268, 154); + this.panel2.TabIndex = 5; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1264, 558); + this.Controls.Add(this.panel2); + this.Controls.Add(this.btnDeleteWindow); + this.Controls.Add(this.btnDeleteZone); + this.Controls.Add(this.btnCreateWindow); + this.Controls.Add(this.panel1); + this.Controls.Add(this.btnCreateZone); + this.Controls.Add(this.pbxInput); + this.Name = "Form1"; + this.Text = "OCR tester"; + ((System.ComponentModel.ISupportInitialize)(this.pbxInput)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox pbxInput; + private System.Windows.Forms.Button btnCreateZone; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Button btnCreateWindow; + private System.Windows.Forms.Button btnDeleteZone; + private System.Windows.Forms.Button btnDeleteWindow; + private System.Windows.Forms.Panel panel2; + } +} + diff --git a/OCR_tester/Form1.cs b/OCR_tester/Form1.cs new file mode 100644 index 0000000..221c7ef --- /dev/null +++ b/OCR_tester/Form1.cs @@ -0,0 +1,89 @@ +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(); + } + + } + } + } +} diff --git a/OCR_tester/Form1.resx b/OCR_tester/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/OCR_tester/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OCR_tester/MainZone.cs b/OCR_tester/MainZone.cs new file mode 100644 index 0000000..9eaec69 --- /dev/null +++ b/OCR_tester/MainZone.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using Tesseract; + +namespace OCR_tester +{ + public class MainZone : Zone + { + List detectedText; + public MainZone(Image fullImage, Rectangle bounds) : base(fullImage, bounds) + { + AutoCalibrate(); + } + public void AutoCalibrate() + { + detectedText = new List(); + TesseractEngine engine = new TesseractEngine(Window.tessDataFolder.FullName, "eng", EngineMode.Default); + var tessImage = Pix.LoadFromMemory(Window.ImageToByte(ZoneImage)); + + Page page = engine.Process(tessImage); + using (var iter = page.GetIterator()) + { + iter.Begin(); + do + { + Rect boundingBox; + if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox)) + { + detectedText.Add(new Rectangle(boundingBox.X1, boundingBox.Y1, boundingBox.Width, boundingBox.Height)); + } + //var text = iter.GetText(PageIteratorLevel.Word); + } while (iter.Next(PageIteratorLevel.Word)); + } + + //Now that we have all the detected text we can try to split the zone + + foreach (Rectangle rect in detectedText) + { + //To do + } + } + public Bitmap Draw() + { + Bitmap image = ZoneImage; + Graphics g = Graphics.FromImage(image); + + foreach (Rectangle rect in detectedText) + { + g.DrawRectangle(Pens.Red,rect); + } + image.Save(@"C:\Users\Moi\Desktop\imgDump\test.png"); + return image; + } + + } +} diff --git a/OCR_tester/OCR_tester.csproj b/OCR_tester/OCR_tester.csproj new file mode 100644 index 0000000..24d60cd --- /dev/null +++ b/OCR_tester/OCR_tester.csproj @@ -0,0 +1,99 @@ + + + + + Debug + AnyCPU + {DDADF99C-AA21-4470-9AA4-E5C6E938D0B2} + WinExe + OCR_tester + OCR_tester + v4.7.2 + 512 + true + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + ..\packages\Tesseract.5.2.0\lib\net47\Tesseract.dll + + + + + Form + + + Form1.cs + + + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/OCR_tester/Program.cs b/OCR_tester/Program.cs new file mode 100644 index 0000000..baa71c3 --- /dev/null +++ b/OCR_tester/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace OCR_tester +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/OCR_tester/Properties/AssemblyInfo.cs b/OCR_tester/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8619a0e --- /dev/null +++ b/OCR_tester/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OCR_tester")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OCR_tester")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ddadf99c-aa21-4470-9aa4-e5c6e938d0b2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OCR_tester/Properties/Resources.Designer.cs b/OCR_tester/Properties/Resources.Designer.cs new file mode 100644 index 0000000..cad68c4 --- /dev/null +++ b/OCR_tester/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace OCR_tester.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OCR_tester.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/OCR_tester/Properties/Resources.resx b/OCR_tester/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/OCR_tester/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OCR_tester/Properties/Settings.Designer.cs b/OCR_tester/Properties/Settings.Designer.cs new file mode 100644 index 0000000..5f0f150 --- /dev/null +++ b/OCR_tester/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace OCR_tester.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/OCR_tester/Properties/Settings.settings b/OCR_tester/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/OCR_tester/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/OCR_tester/Window.cs b/OCR_tester/Window.cs new file mode 100644 index 0000000..d7f64ca --- /dev/null +++ b/OCR_tester/Window.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; +using System.IO; + +namespace OCR_tester +{ + public class Window + { + private Bitmap FullImage; + + private Rectangle _bounds; + public Rectangle Bounds { get => _bounds; private set => _bounds = value; } + + public static DirectoryInfo tessDataFolder = new DirectoryInfo(@"C:\Users\Moi\Pictures\SeleniumScreens\TessData"); + + public Bitmap WindowImage + { + get + { + Bitmap sample = new Bitmap(Bounds.Width, Bounds.Height); + Graphics g = Graphics.FromImage(sample); + g.DrawImage(FullImage, new Rectangle(0, 0, sample.Width, sample.Height), Bounds, GraphicsUnit.Pixel); + return sample; + } + } + public Window(Bitmap fullImage, Rectangle bounds) + { + FullImage = fullImage; + Bounds = bounds; + } + public virtual void RecoverInformations() + { + //Each Window type will have to implement its own way to recover the informations stored in the Window Image + } + public static byte[] ImageToByte(Image img) + { + using (var stream = new MemoryStream()) + { + img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); + return stream.ToArray(); + } + } + } +} diff --git a/OCR_tester/Zone.cs b/OCR_tester/Zone.cs new file mode 100644 index 0000000..533f395 --- /dev/null +++ b/OCR_tester/Zone.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; + +namespace OCR_tester +{ + public class Zone + { + private Bitmap FullImage; + private List Zones; + private List Windows; + + private Rectangle _bounds; + public Rectangle Bounds { get => _bounds; private set => _bounds = value; } + + public Bitmap ZoneImage + { + get + { + Bitmap sample = new Bitmap(Bounds.Width, Bounds.Height); + Graphics g = Graphics.FromImage(sample); + g.DrawImage(FullImage, new Rectangle(0, 0, sample.Width, sample.Height), Bounds, GraphicsUnit.Pixel); + return sample; + } + } + + public Zone(Image fullImage, Rectangle bounds) + { + FullImage = (Bitmap)fullImage; + Init(bounds); + } + public Zone(Bitmap fullImage, Rectangle bounds) + { + FullImage = fullImage; + Init(bounds); + } + private void Init(Rectangle bounds) + { + Bounds = bounds; + Zones = new List(); + Windows = new List(); + } + public void AddZone(Rectangle bounds) + { + if(Fits(bounds)) + Zones.Add(new Zone(ZoneImage,bounds)); + } + public void AddWindow(Rectangle bounds) + { + if (Fits(bounds)) + Windows.Add(new Window(ZoneImage,bounds)); + } + /// + /// Checks if the given Rectangle fits in the current zone + /// + /// The Rectangle you want to check the fittment + /// + private bool Fits(Rectangle inputRectangle) + { + if (inputRectangle.X + inputRectangle.Width > Bounds.Width || inputRectangle.Y + inputRectangle.Height > Bounds.Height || inputRectangle.X < 0 || inputRectangle.Y < 0) + { + return false; + } + else + { + return true; + } + } + } +} diff --git a/OCR_tester/packages.config b/OCR_tester/packages.config new file mode 100644 index 0000000..bc3f6cb --- /dev/null +++ b/OCR_tester/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..3b789b1 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,3 @@ +# ReadMe + +Project used to test the OCR. Currently in WIP \ No newline at end of file