Take the 2-minute tour ×

I have the current code:

    Dim Bitmap As New Bitmap("image.png")
    Dim ocr As tessnet2.Tesseract = New tessnet2.Tesseract()
    ocr.SetVariable("tessedit_char_whitelit", "0123456789")
    ocr.Init("c:\", "fra", False)
    Dim result As List(Of tessnet2.Word) = ocr.DoOCR(Bitmap, Rectangle.Empty)
    For Each word As tessnet2.Word In result
        RichTextBox1.Text &= word.Text & "(" & word.Confidence & ") "
End Sub

I just have a normal RichTextBox and a button on the form. I also have an image in the debug directory called "image.png".

Every time I run this, the program just closes. I did a step through and all of a sudden a file locater came up asking for "tessnet2.cpp"

I have a reference to the dll. I also don't know what the ocr.Init(...) line is for.

Any help would be nice!

share|improve this question
This line ocr.SetVariable("tessedit_char_whitelit", "0123456789") should be ocr.SetVariable("tessedit_char_whitelist", "0123456789") –  Mitch Wheat Apr 10 '11 at 1:47
Are you running with admin permissions? –  Mitch Wheat Apr 10 '11 at 1:50
ocr.init() tells the dll where the language files are. Looks like you are using French? –  Mitch Wheat Apr 10 '11 at 1:52
Ok, where would I find the language normally stored at? –  Xander Apr 10 '11 at 19:40

3 Answers 3

up vote 1 down vote accepted

First of all, thank you very much for your simple but effective code. After 3 days search I found this code for VB (not VC). Of course I copied and pasted it immediately and the same problem occured for me, too. Then:

  1. I uninstalled Tesseract 3.xx
  2. Checked RegEdit for Tesseract 3.xx and deleted them (whoever want to do this step; please be careful not to destroy anything)
  3. Copied tessdll.dll in the same folder.

  4. The main problem is: ocr.Init("c:\", "fra", False) it should be something like this: ocr.Init("c:\tessdata", "fra", False) in fact my real line is: ocr.Init(Application.StartupPath & "\tessdata", "eng", False)

  5. Noticed that in the folder "...\Visual Studio 2008\Projects...." I still had the same problem and then copied all folder in "D:\Test" folder (of course in this folder I have one more folder: tessdata)

It worked!!!

Hope it helps for you or anyone searching for this problem like me :)


share|improve this answer
Wow, thanks! I've never been able to get this to work until now! –  Xander Apr 19 '12 at 21:49

If you put your code inside a Try/Catch block, you should be able to find out what the error is without your program closing. You could also debug the program instead of running it, and instead of the program crashing, the debugger will show you exactly where the error is happening.

share|improve this answer
Right, use the debugger. That's what it's for. Don't needlessly litter your source code with try/catch blocks. You'll just forget to take them out, hiding real errors from view. –  Cody Gray Apr 10 '11 at 7:00
I am debugging. Nothing is thrown. It just closes. –  Xander Apr 10 '11 at 19:41

The first parameter of Init method specifies the location of tessdata folder. If you have it at the default location, which is the same as that of Tesseract binary, it should be null, or Nothing in VB.NET.

share|improve this answer

Your Answer


