Optical Character Recognition (OCR) in C#
This post will help you to create an OCR application in C#. For this,
After downloading, run the installer to install Puma.NET on your device. The default installation folder will be C:\ProgramFiles (x86) on 32 bit systems. After finishing installation you will have three folders under C:\ProgramFiles (x86)\Puma.NET.
Open Assemblies folder and there you will have three DLLs named dibapi.dll, puma.interop.dll and Puma.Net.dll.
- Create a Windows Forms Application and add a Button and RichTextBox to the form.
- Right click on Project -> Add References.
- Select Browse and add Puma.Net.dll from the Assemblies folder under installation path of Puma.NET.
- Click on Build to build your project.
- Open Debug folder of the project and there will be puma.interop.dll and Puma.Net.dll in the folder.
- Copy dibapi.dl (C:\ProgramFiles (x86)\Puma.NET\Assemblies) to the Debug folder of your project. This is how the Debug folder will look like.
- Double click on the Browse button to create an event handler for the button and add this code.
OpenFileDialog file = new OpenFileDialog();
file.Multiselect = false;
if (file.ShowDialog() == DialogResult.OK)
string path = file.FileName;
Puma.Net.PumaPage input = new Puma.Net.PumaPage(path);
input.FileFormat = Puma.Net.PumaFileFormat.TxtAscii;
input.Language = Puma.Net.PumaLanguage.English;
string result = input.RecognizeToString();
richTextBox1.Text = result;
Now your code will look like
- Run the application and click on the Button and select an image which contains text.
Download Source code.