Click here to Skip to main content
13,252,065 members (57,071 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

37.9K views
10 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

saramgsilva
Software Developer (Senior)
Portugal Portugal
I am Sara Silva, i studied mathematics in University of Coimbra, but since i finish my degree I’m working in software development using Microsoft technologies.

Nowadays I am a Windows 8 Store, Windows Phone, Xamarin and Azure Developer in Portugal, with experience in the development of projects within the operational planning of public transport, logistics, payments and multimedia.

I was awarded

Telerik Developer Expert
Microsoft Most Valuable Professional (MVP) 2015 – .Net
Microsoft Most Valuable Professional (MVP) 2014 – Visual C#
Microsoft Most Valuable Professional (MVP) 2013 – Visual C#
C# Corner Most Valuable Professional (MVP)
Nokia Developer Champion


Others awards:

Nokia Developer Wiki Contributor of the Month for March 2013
Nokia Developer Wiki Contributor of the Month for November 2013
Nokia Developer Wiki Contributor of the Month for August 2014
TechNet Wiki – Longest Article Award – May, September 2014
TechNet Wiki – Windows Phone and Windows Store Apps Technical Guru – May, June, July, August, September, October 2014
TechNet Wiki – Microsoft Azure Technical Guru – July, September, October 2014
TechNet Wiki – Visual C# Technical Guru – August, October 2014
TechNet Wiki – Miscellaneous Technical Guru – August, October 2014
TechNet Wiki – WPF Technical Guru – October, November 2014
Curah! 2014 Award – Top 10 featured curators


My profissional profile:

Windows 8 Store Apps Developer
Windows Phone Developer
WPF Developer
Xamarin Developer
Azure Developer


My Certifications:

MCTS: .NET Framework 4.0, Windows Applications
MCPD: Windows Developer 3.5
MCTS: .NET Framework 3.5, Windows Forms Applications
MCTS: .NET Framework 3.5 Windows Presentation Foundation Applications

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionTessnet2 is deprecated... Pin
ezio200025-Aug-15 0:49
memberezio200025-Aug-15 0:49 
QuestionTessnet2 not reading words correctly Pin
Member 1176598828-Jul-15 0:34
memberMember 1176598828-Jul-15 0:34 
QuestionThank you. Pin
Member 1132684420-Jun-15 11:44
memberMember 1132684420-Jun-15 11:44 
QuestionNice! It worked fine with numbers Pin
Igor Campos15-Apr-15 8:23
memberIgor Campos15-Apr-15 8:23 
QuestionCan this be used with Xamarin Pin
Gboye5-Apr-15 23:00
memberGboye5-Apr-15 23:00 
QuestionTessnet2 in C# is reading only one word Pin
Praveen Chougale31-Jan-15 0:32
memberPraveen Chougale31-Jan-15 0:32 
GeneralMy vote of 2 Pin
Pruthviraj Mohite18-May-14 23:45
memberPruthviraj Mohite18-May-14 23: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
Web02 | 2.8.171114.1 | Last Updated 14 Dec 2013
Article Copyright 2013 by saramgsilva
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid