在VB.net中使用Tesseract时出现奇怪的错误 [英] Strange Error When Using Tesseract in VB.net
问题描述
我有当前代码:
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
我只有一个普通的RichTextBox和一个按钮在表单上.我在调试目录中也有一个名为"image.png"的图像.
I just have a normal RichTextBox and a button on the form. I also have an image in the debug directory called "image.png".
每次我运行此程序时,程序都会关闭.我经过了一步,突然有一个文件定位器出现,要求"tessnet2.cpp"
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"
我对dll有参考.我也不知道ocr.Init(...)行是做什么的.
I have a reference to the dll. I also don't know what the ocr.Init(...) line is for.
任何帮助都会很好!
推荐答案
首先,非常感谢您提供了简单但有效的代码.经过三天的搜索,我找到了此代码的VB(不是VC).当然,我立即复制并粘贴了它,同样的问题也发生在我身上.然后:
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:
- 我卸载了Tesseract 3.xx
- 检查了Tesseract 3.xx的RegEdit,并删除了它们(无论谁想要执行此步骤;请注意不要破坏任何东西)
-
在同一文件夹中复制了tessdll.dll.
- I uninstalled Tesseract 3.xx
- Checked RegEdit for Tesseract 3.xx and deleted them (whoever want to do this step; please be careful not to destroy anything)
Copied tessdll.dll in the same folder.
主要问题是:
ocr.Init("c:\", "fra", False)
应该是这样的:
ocr.Init("c:\tessdata", "fra", False)
实际上,我的真实想法是:
ocr.Init(Application.StartupPath & "\tessdata", "eng", False)
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)
忽略了文件夹"... \ Visual Studio 2008 \ Projects ...."中的问题,然后将所有文件夹复制到了"D:\ Test"文件夹中(当然在此文件夹我还有一个文件夹:tessdata)
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)
成功了!
希望它对您或像我这样搜索此问题的人有所帮助:)
Hope it helps for you or anyone searching for this problem like me :)
是
这篇关于在VB.net中使用Tesseract时出现奇怪的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!