Click here to Skip to main content
13,511,029 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

41.4K views
11 bookmarked
Posted 13 Dec 2013

How to Use Tessnet2 Library

, 13 Dec 2013
Rate this:
Please Sign up or sign in to vote.
This article aims to show how to use the Tessnet2 library.

This article has the goal to show how to use the Tessnet2 library.

Tessnet2 is a .NET 2.0 Open Source OCR assembly using Tesseract engine. Download binary here.

Another important thing for Tessnet2 work is get the languages packages, get it here for the languages you want. For the sample, we are using the English language.

Let’s start the sample.

Create one console application:

console aplication

Then copy the folder with binaries and languages packages to the same folder.
Note: Don't forget to unzip the languages packages until you have the tessdata folder with eng.DangAmbigs, eng.freq-dawg, eng.inttemp, eng.normproto, eng.pffmtable, eng.unicharset, eng.user-words and eng.word-dawg files.

The aspect should be something like:

ocr test folder

Now add the Tessnet2 reference to the project, do a right click in References > Add References > Browse> Select the folder with C:\OCRTest\tessnet2\Release64\tessnet2_64.dll and click Ok.

After add the reference for System.Drawing:

reference

Now, we need to configure the project to compile in x64, for it Right Click in project> Properties>Build> Platform target.

configs

In Program.cs, add the following code:

static void Main(string[] args)
        {
            try
            {
                var image = new Bitmap(@"C:\OCRTest\number.jpg");
                var ocr = new Tesseract();
                ocr.SetVariable("tessedit_char_whitelist", "0123456789"); // If digit only
                //@"C:\OCRTest\tessdata" contains 
                //the language package, without this the method crash and app breaks
                ocr.Init(@"C:\OCRTest\tessdata", "eng", true); 
                var result = ocr.DoOCR(image, Rectangle.Empty);
                foreach (Word word in result)
                    Console.WriteLine("{0} : {1}", word.Confidence, word.Text);

                Console.ReadLine();
            }
            catch (Exception exception)
            {

            }
        }

and run the application, this gives an error:

error

To solve this, go to directory and change the App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

For the test:

test

The result is:

result

You can download the source code here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionTessnet2 is deprecated... Pin
ezio200024-Aug-15 23:49
memberezio200024-Aug-15 23:49 
QuestionTessnet2 not reading words correctly Pin
Member 1176598827-Jul-15 23:34
memberMember 1176598827-Jul-15 23:34 
QuestionThank you. Pin
Member 1132684420-Jun-15 10:44
memberMember 1132684420-Jun-15 10:44 
QuestionNice! It worked fine with numbers Pin
Igor Campos15-Apr-15 7:23
memberIgor Campos15-Apr-15 7:23 
QuestionCan this be used with Xamarin Pin
Gboye5-Apr-15 22:00
memberGboye5-Apr-15 22:00 
QuestionTessnet2 in C# is reading only one word Pin
Praveen Chougale30-Jan-15 23:32
memberPraveen Chougale30-Jan-15 23:32 
GeneralMy vote of 2 Pin
Pruthviraj Mohite18-May-14 22:45
memberPruthviraj Mohite18-May-14 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180417.1 | Last Updated 14 Dec 2013
Article Copyright 2013 by saramgsilva
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid