├── .gitignore ├── APITest ├── App.config ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── MyFormUrlEncodedContent.cs ├── OCR-API-Test.csproj ├── OCRResult.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── packages.config ├── LICENSE ├── OCR-API-Test.sln ├── README.md ├── Test Images ├── chi-scan-100dpi-verygood.jpg ├── eng-screenshot-verygood.jpg ├── eng-smartphone-ok.jpg ├── toobig-error.png └── tooblurry-error.jpg └── ocr.space api test app.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /APITest/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /APITest/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace OCRAPITest 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.pictureBox = new System.Windows.Forms.PictureBox(); 32 | this.button1 = new System.Windows.Forms.Button(); 33 | this.txtResult = new System.Windows.Forms.TextBox(); 34 | this.button2 = new System.Windows.Forms.Button(); 35 | this.cmbLanguage = new System.Windows.Forms.ComboBox(); 36 | this.label1 = new System.Windows.Forms.Label(); 37 | this.btnPDF = new System.Windows.Forms.Button(); 38 | this.lblInfo = new System.Windows.Forms.Label(); 39 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); 40 | this.SuspendLayout(); 41 | // 42 | // pictureBox 43 | // 44 | this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 45 | | System.Windows.Forms.AnchorStyles.Left) 46 | | System.Windows.Forms.AnchorStyles.Right))); 47 | this.pictureBox.BackColor = System.Drawing.Color.White; 48 | this.pictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 49 | this.pictureBox.Location = new System.Drawing.Point(12, 45); 50 | this.pictureBox.Name = "pictureBox"; 51 | this.pictureBox.Size = new System.Drawing.Size(265, 250); 52 | this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 53 | this.pictureBox.TabIndex = 0; 54 | this.pictureBox.TabStop = false; 55 | // 56 | // button1 57 | // 58 | this.button1.Location = new System.Drawing.Point(13, 12); 59 | this.button1.Name = "button1"; 60 | this.button1.Size = new System.Drawing.Size(95, 23); 61 | this.button1.TabIndex = 1; 62 | this.button1.Text = "Load Image"; 63 | this.button1.UseVisualStyleBackColor = true; 64 | this.button1.Click += new System.EventHandler(this.button1_Click); 65 | // 66 | // txtResult 67 | // 68 | this.txtResult.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 69 | | System.Windows.Forms.AnchorStyles.Right))); 70 | this.txtResult.Location = new System.Drawing.Point(365, 45); 71 | this.txtResult.Multiline = true; 72 | this.txtResult.Name = "txtResult"; 73 | this.txtResult.Size = new System.Drawing.Size(304, 250); 74 | this.txtResult.TabIndex = 2; 75 | // 76 | // button2 77 | // 78 | this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right; 79 | this.button2.Location = new System.Drawing.Point(284, 132); 80 | this.button2.Name = "button2"; 81 | this.button2.Size = new System.Drawing.Size(75, 61); 82 | this.button2.TabIndex = 3; 83 | this.button2.Text = "Recognize"; 84 | this.button2.UseVisualStyleBackColor = true; 85 | this.button2.Click += new System.EventHandler(this.button2_Click); 86 | // 87 | // cmbLanguage 88 | // 89 | this.cmbLanguage.FormattingEnabled = true; 90 | this.cmbLanguage.Items.AddRange(new object[] { 91 | "Arabic", 92 | "ChineseSimplified", 93 | "ChineseTraditional ", 94 | "Czech", 95 | "Danish", 96 | "Dutch", 97 | "English", 98 | "Finnish", 99 | "French", 100 | "German", 101 | "Greek ", 102 | "Hungarian", 103 | "Italian", 104 | "Japanese", 105 | "Korean ", 106 | "Norwegian", 107 | "Polish", 108 | "Portuguese", 109 | "Russian ", 110 | "Spanish", 111 | "Swedish ", 112 | "Turkish"}); 113 | this.cmbLanguage.Location = new System.Drawing.Point(498, 17); 114 | this.cmbLanguage.Name = "cmbLanguage"; 115 | this.cmbLanguage.Size = new System.Drawing.Size(124, 21); 116 | this.cmbLanguage.TabIndex = 4; 117 | // 118 | // label1 119 | // 120 | this.label1.AutoSize = true; 121 | this.label1.Location = new System.Drawing.Point(437, 20); 122 | this.label1.Name = "label1"; 123 | this.label1.Size = new System.Drawing.Size(55, 13); 124 | this.label1.TabIndex = 5; 125 | this.label1.Text = "Language"; 126 | // 127 | // btnPDF 128 | // 129 | this.btnPDF.Location = new System.Drawing.Point(131, 12); 130 | this.btnPDF.Name = "btnPDF"; 131 | this.btnPDF.Size = new System.Drawing.Size(95, 23); 132 | this.btnPDF.TabIndex = 6; 133 | this.btnPDF.Text = "Load PDF"; 134 | this.btnPDF.UseVisualStyleBackColor = true; 135 | this.btnPDF.Click += new System.EventHandler(this.btnPDF_Click); 136 | // 137 | // lblInfo 138 | // 139 | this.lblInfo.AutoSize = true; 140 | this.lblInfo.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); 141 | this.lblInfo.Location = new System.Drawing.Point(12, 298); 142 | this.lblInfo.Name = "lblInfo"; 143 | this.lblInfo.Size = new System.Drawing.Size(158, 13); 144 | this.lblInfo.TabIndex = 7; 145 | this.lblInfo.Text = "(Filename will be displayed here)"; 146 | // 147 | // Form1 148 | // 149 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 150 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 151 | this.ClientSize = new System.Drawing.Size(681, 313); 152 | this.Controls.Add(this.lblInfo); 153 | this.Controls.Add(this.btnPDF); 154 | this.Controls.Add(this.label1); 155 | this.Controls.Add(this.cmbLanguage); 156 | this.Controls.Add(this.button2); 157 | this.Controls.Add(this.txtResult); 158 | this.Controls.Add(this.button1); 159 | this.Controls.Add(this.pictureBox); 160 | this.Name = "Form1"; 161 | this.Text = "OCR.SPACE Free OCR API - Test App"; 162 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); 163 | this.ResumeLayout(false); 164 | this.PerformLayout(); 165 | 166 | } 167 | 168 | #endregion 169 | 170 | private System.Windows.Forms.PictureBox pictureBox; 171 | private System.Windows.Forms.Button button1; 172 | private System.Windows.Forms.TextBox txtResult; 173 | private System.Windows.Forms.Button button2; 174 | private System.Windows.Forms.ComboBox cmbLanguage; 175 | private System.Windows.Forms.Label label1; 176 | private System.Windows.Forms.Button btnPDF; 177 | private System.Windows.Forms.Label lblInfo; 178 | } 179 | } 180 | 181 | -------------------------------------------------------------------------------- /APITest/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | using System.Net.Http; 6 | using System.IO; 7 | using Newtonsoft.Json; 8 | 9 | 10 | namespace OCRAPITest 11 | { 12 | public partial class Form1 : Form 13 | { 14 | 15 | public string ImagePath { get; set; } 16 | public string PdfPath { get; set; } 17 | 18 | public Form1() 19 | { 20 | InitializeComponent(); 21 | cmbLanguage.SelectedIndex = 6;//English 22 | } 23 | 24 | private string getSelectedLanguage() 25 | { 26 | 27 | //https://ocr.space/OCRAPI#PostParameters 28 | 29 | //Czech = cze; Danish = dan; Dutch = dut; English = eng; Finnish = fin; French = fre; 30 | //German = ger; Hungarian = hun; Italian = ita; Norwegian = nor; Polish = pol; Portuguese = por; 31 | //Spanish = spa; Swedish = swe; ChineseSimplified = chs; Greek = gre; Japanese = jpn; Russian = rus; 32 | //Turkish = tur; ChineseTraditional = cht; Korean = kor 33 | 34 | string strLang = ""; 35 | switch (cmbLanguage.SelectedIndex) 36 | { 37 | case 0: 38 | strLang = "ara"; 39 | break; 40 | 41 | case 1: 42 | strLang = "chs"; 43 | break; 44 | 45 | case 2: 46 | strLang = "cht"; 47 | break; 48 | case 3: 49 | strLang = "cze"; 50 | break; 51 | case 4: 52 | strLang = "dan"; 53 | break; 54 | case 5: 55 | strLang = "dut"; 56 | break; 57 | case 6: 58 | strLang = "eng"; 59 | break; 60 | case 7: 61 | strLang = "fin"; 62 | break; 63 | case 8: 64 | strLang = "fre"; 65 | break; 66 | case 9: 67 | strLang = "ger"; 68 | break; 69 | case 10: 70 | strLang = "gre"; 71 | break; 72 | case 11: 73 | strLang = "hun"; 74 | break; 75 | case 12: 76 | strLang = "jap"; 77 | break; 78 | case 13: 79 | strLang = "kor"; 80 | break; 81 | case 14: 82 | strLang = "nor"; 83 | break; 84 | case 15: 85 | strLang = "pol"; 86 | break; 87 | case 16: 88 | strLang = "por"; 89 | break; 90 | case 17: 91 | strLang = "spa"; 92 | break; 93 | case 18: 94 | strLang = "swe"; 95 | break; 96 | case 19: 97 | strLang = "tur"; 98 | break; 99 | 100 | } 101 | return strLang; 102 | 103 | } 104 | 105 | private void button1_Click(object sender, EventArgs e) 106 | { 107 | PdfPath = ImagePath = ""; pictureBox.BackgroundImage = null; 108 | OpenFileDialog fileDlg = new OpenFileDialog(); 109 | fileDlg.Filter = "jpeg and png files|*.png;*.jpg;*.JPG"; 110 | if (fileDlg.ShowDialog() == DialogResult.OK) 111 | { 112 | FileInfo fileInfo = new FileInfo(fileDlg.FileName); 113 | if (fileInfo.Length > 5* 1024 * 1024) 114 | { 115 | //Size limit depends: Free API 1 MB, PRO API 5 MB and more 116 | MessageBox.Show("Image file size limit reached (1MB free API)"); 117 | return; 118 | } 119 | pictureBox.BackgroundImage = Image.FromFile(fileDlg.FileName); 120 | ImagePath = fileDlg.FileName; 121 | lblInfo.Text = "Image loaded: "+ fileInfo.Name; 122 | lblInfo.BackColor = Color.LightGreen; 123 | } 124 | } 125 | 126 | private void btnPDF_Click(object sender, EventArgs e) 127 | { 128 | PdfPath = ImagePath = ""; 129 | pictureBox.BackgroundImage = null; 130 | OpenFileDialog fileDlg = new OpenFileDialog(); 131 | fileDlg.Filter = "pdf files|*.pdf;"; 132 | if (fileDlg.ShowDialog() == DialogResult.OK) 133 | { 134 | FileInfo fileInfo = new FileInfo(fileDlg.FileName); 135 | if (fileInfo.Length > 5* 1024 * 1024 ) 136 | { 137 | //Size limit depends: Free API 1 MB, PRO API 5 MB and more 138 | MessageBox.Show("PDF file size should not be larger than 5Mb"); 139 | return; 140 | } 141 | PdfPath = fileDlg.FileName; 142 | //PDF files are loaded, but can not be displayed in the image control. That does not affect the OCR. 143 | lblInfo.Text = "PDF loaded [but not displayed]: " + fileInfo.Name; 144 | lblInfo.BackColor = Color.LightSalmon; 145 | } 146 | } 147 | 148 | private byte[] ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format) 149 | { 150 | using (MemoryStream ms = new MemoryStream()) 151 | { 152 | // Convert Image to byte[] 153 | image.Save(ms, format); 154 | byte[] imageBytes = ms.ToArray(); 155 | 156 | return imageBytes; 157 | } 158 | } 159 | 160 | private async void button2_Click(object sender, EventArgs e) 161 | { 162 | 163 | 164 | if (string.IsNullOrEmpty(ImagePath) && string.IsNullOrEmpty(PdfPath)) 165 | return; 166 | 167 | txtResult.Text = ""; 168 | 169 | button1.Enabled = false; 170 | button2.Enabled = false; 171 | btnPDF.Enabled = false; 172 | 173 | try 174 | { 175 | HttpClient httpClient = new HttpClient(); 176 | httpClient.Timeout = new TimeSpan(1, 1, 1); 177 | 178 | 179 | MultipartFormDataContent form = new MultipartFormDataContent(); 180 | form.Add(new StringContent("helloworld"), "apikey"); //Added api key in form data 181 | form.Add(new StringContent(getSelectedLanguage()), "language"); 182 | 183 | form.Add(new StringContent("2"), "ocrengine"); 184 | form.Add(new StringContent("true"), "scale"); 185 | form.Add(new StringContent("true"), "istable"); 186 | 187 | if (string.IsNullOrEmpty(ImagePath) == false) 188 | { 189 | byte[] imageData = File.ReadAllBytes(ImagePath); 190 | form.Add(new ByteArrayContent(imageData, 0, imageData.Length), "image", "image.jpg"); 191 | } 192 | else if (string.IsNullOrEmpty(PdfPath) == false) 193 | { 194 | byte[] imageData = File.ReadAllBytes(PdfPath); 195 | form.Add(new ByteArrayContent(imageData, 0, imageData.Length), "PDF", "pdf.pdf"); 196 | } 197 | 198 | HttpResponseMessage response = await httpClient.PostAsync("https://api.ocr.space/Parse/Image", form); 199 | 200 | string strContent = await response.Content.ReadAsStringAsync(); 201 | 202 | 203 | 204 | Rootobject ocrResult = JsonConvert.DeserializeObject(strContent); 205 | 206 | 207 | if (ocrResult.OCRExitCode == 1) 208 | { 209 | for (int i = 0; i < ocrResult.ParsedResults.Count() ; i++) 210 | { 211 | txtResult.Text = txtResult.Text + ocrResult.ParsedResults[i].ParsedText ; 212 | } 213 | } 214 | else 215 | { 216 | MessageBox.Show("ERROR: " + strContent); 217 | } 218 | 219 | 220 | 221 | } 222 | catch (Exception exception) 223 | { 224 | MessageBox.Show("Ooops"); 225 | } 226 | 227 | button1.Enabled = true; 228 | button2.Enabled = true; 229 | btnPDF.Enabled = true; 230 | } 231 | 232 | 233 | } 234 | } 235 | 236 | 237 | 238 | -------------------------------------------------------------------------------- /APITest/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /APITest/MyFormUrlEncodedContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Net.Http; 5 | using System.Net.Http.Headers; 6 | 7 | namespace OCRAPITest 8 | { 9 | public class MyFormUrlEncodedContent : ByteArrayContent 10 | { 11 | public MyFormUrlEncodedContent(IEnumerable> nameValueCollection) 12 | : base(MyFormUrlEncodedContent.GetContentByteArray(nameValueCollection)) 13 | { 14 | base.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); 15 | } 16 | private static byte[] GetContentByteArray(IEnumerable> nameValueCollection) 17 | { 18 | if (nameValueCollection == null) 19 | { 20 | throw new ArgumentNullException("nameValueCollection"); 21 | } 22 | StringBuilder stringBuilder = new StringBuilder(); 23 | foreach (KeyValuePair current in nameValueCollection) 24 | { 25 | if (stringBuilder.Length > 0) 26 | { 27 | stringBuilder.Append('&'); 28 | } 29 | 30 | stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Key)); 31 | stringBuilder.Append('='); 32 | stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Value)); 33 | } 34 | return Encoding.Default.GetBytes(stringBuilder.ToString()); 35 | } 36 | private static string Encode(string data) 37 | { 38 | if (string.IsNullOrEmpty(data)) 39 | { 40 | return string.Empty; 41 | } 42 | return System.Net.WebUtility.UrlEncode(data).Replace("%20", "+"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /APITest/OCR-API-Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {A5220CB6-5B6A-4F55-9086-7CF179AEE042} 8 | WinExe 9 | Properties 10 | OCRAPITest 11 | OCRAPITest 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll 37 | True 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Form 54 | 55 | 56 | Form1.cs 57 | 58 | 59 | 60 | 61 | 62 | 63 | Form1.cs 64 | 65 | 66 | ResXFileCodeGenerator 67 | Resources.Designer.cs 68 | Designer 69 | 70 | 71 | True 72 | Resources.resx 73 | True 74 | 75 | 76 | 77 | SettingsSingleFileGenerator 78 | Settings.Designer.cs 79 | 80 | 81 | True 82 | Settings.settings 83 | True 84 | 85 | 86 | 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /APITest/OCRResult.cs: -------------------------------------------------------------------------------- 1 | namespace OCRAPITest 2 | { 3 | 4 | public class Rootobject 5 | { 6 | public Parsedresult[] ParsedResults { get; set; } 7 | public int OCRExitCode { get; set; } 8 | public bool IsErroredOnProcessing { get; set; } 9 | public string ErrorMessage { get; set; } 10 | public string ErrorDetails { get; set; } 11 | } 12 | 13 | public class Parsedresult 14 | { 15 | public object FileParseExitCode { get; set; } 16 | public string ParsedText { get; set; } 17 | public string ErrorMessage { get; set; } 18 | public string ErrorDetails { get; set; } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /APITest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace OCRAPITest 5 | { 6 | static class Program 7 | { 8 | /// 9 | /// The main entry point for the application. 10 | /// 11 | [STAThread] 12 | static void Main() 13 | { 14 | Application.EnableVisualStyles(); 15 | Application.SetCompatibleTextRenderingDefault(false); 16 | Application.Run(new Form1()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /APITest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("BaiduAPITest")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("BaiduAPITest")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("ee380f6e-d43f-4ff9-b4c2-3075ede4e59f")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /APITest/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace OCRAPITest.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OCRAPITest.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /APITest/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /APITest/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace OCRAPITest.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /APITest/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /APITest/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 A9T9 (Autonomous Technology Blog) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /OCR-API-Test.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OCR-API-Test", "APITest\OCR-API-Test.csproj", "{A5220CB6-5B6A-4F55-9086-7CF179AEE042}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {A5220CB6-5B6A-4F55-9086-7CF179AEE042}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {A5220CB6-5B6A-4F55-9086-7CF179AEE042}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {A5220CB6-5B6A-4F55-9086-7CF179AEE042}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {A5220CB6-5B6A-4F55-9086-7CF179AEE042}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Free-OCR-API-CSharp 2 | Web API test app for the OCR.SPACE Free OCR API as Visual Studio C# project. 3 | 4 | Update May 11: Added support for sending PDF documents 5 | 6 | For an ASP.NET example project see https://github.com/A9T9/Free-OCR-API-ASP.NET 7 | -------------------------------------------------------------------------------- /Test Images/chi-scan-100dpi-verygood.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A9T9/Free-OCR-API-CSharp/b14fc0b4541b3948f602ba70b1fdeae7ec9f7a56/Test Images/chi-scan-100dpi-verygood.jpg -------------------------------------------------------------------------------- /Test Images/eng-screenshot-verygood.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A9T9/Free-OCR-API-CSharp/b14fc0b4541b3948f602ba70b1fdeae7ec9f7a56/Test Images/eng-screenshot-verygood.jpg -------------------------------------------------------------------------------- /Test Images/eng-smartphone-ok.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A9T9/Free-OCR-API-CSharp/b14fc0b4541b3948f602ba70b1fdeae7ec9f7a56/Test Images/eng-smartphone-ok.jpg -------------------------------------------------------------------------------- /Test Images/toobig-error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A9T9/Free-OCR-API-CSharp/b14fc0b4541b3948f602ba70b1fdeae7ec9f7a56/Test Images/toobig-error.png -------------------------------------------------------------------------------- /Test Images/tooblurry-error.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A9T9/Free-OCR-API-CSharp/b14fc0b4541b3948f602ba70b1fdeae7ec9f7a56/Test Images/tooblurry-error.jpg -------------------------------------------------------------------------------- /ocr.space api test app.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A9T9/Free-OCR-API-CSharp/b14fc0b4541b3948f602ba70b1fdeae7ec9f7a56/ocr.space api test app.jpg --------------------------------------------------------------------------------