Optical Charactor Recognition (OCR) in C#

This post will help you to create an OCR application in C#. For this i will be using Visual Studio 2013 and Puma.NET. Before creating the project you need to install Puma.NET on your computer. You can download Puma.NET from here

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;
                if (!string.IsNullOrEmpty(path))
                {
                    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();
                    input.Dispose();
                    richTextBox1.Text = result;
                }
            }

 Now your code will look like
  •  Run the application and click on the Button and select an image which contains text.

Output:

 

Picture i have used is:
 

Download Source code.

Comments

  1. Hi! It is impossible to download PUMA.NET from the site you mentioned because codeplex.com has stopped its activity. So it would be great if you share these materials somewhere else. Thanks a lot !

    ReplyDelete
  2. pumanet.zip -> releases -> 0 -> 58a62dd0-265a-4e6b-a797-74082989fd8e достань этот файл и переименуй в PumaNET.msi

    Добавлено через 1 минуту
    а вообще в той папке:
    2a4d07d4-3e5b-492f-a399-0599e0d2ea22 -> PumaNET.msi 2009-10-29
    12eaa90c-1940-4528-8b04-88aa20e5f7e8 -> PumaNET.zip 2009-11-02
    58a62dd0-265a-4e6b-a797-74082989fd8e -> PumaNET.msi 2010-01-09

    ReplyDelete

Post a Comment

Popular posts from this blog

How to create a transparent window in Windows Form Application

Installing MASM on Windows (32 bit or 64 bit)