Strange Error When Using Tesseract in VB.net

耗尽温柔 提交于 2020-01-03 05:04:30

问题


I have the current code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    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 & ") "
    Next
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!


回答1:


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 :)

Nes




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/5609204/strange-error-when-using-tesseract-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!