C# tessnet2 加载失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2053575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tessnet2 fails to load
提问by Hyman
i'm using the tessnet2 wrapper to the Tesseract 2.04 Source on windows XP, configured it to work with x86.
我在 Windows XP 上将 tessnet2 包装器用于 Tesseract 2.04 源,将其配置为与 x86 一起使用。
TessarctTest project main function contains:
TessarctTest项目主要功能包含:
Bitmap bmp = new Bitmap(@"C:\temp\New Folder\dotnet\eurotext.tif");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
// ocr.SetVariable("tessedit_char_whitelist", "0123456789");
ocr.Init(@"C:\temp\tessdata", "eng", false);
// List<tessnet2.Word> r1 = ocr.DoOCR(bmp, new Rectangle(792, 247, 130, 54));
List<tessnet2.Word> r1 = ocr.DoOCR(bmp, Rectangle.Empty);
int lc = tessnet2.Tesseract.LineCount(r1);
when i try to run the program it crashes on the following line inside the ocr.Init
当我尝试运行该程序时,它会在 ocr.Init 中的以下行崩溃
int result = m_myTessBaseAPIInstance->InitWithLanguage((char *)_tessdata.ToPointer(), NULL, (char *)_lang.ToPointer(), NULL, numericMode, 0, NULL);
Any one has an idea?
有人有什么想法吗?
Appreciate!
欣赏!
回答by Hans Passant
Project + Properties, Debug tab, scroll down, tick the "Enable unmanaged code debugging" checkbox. Now you can set a breakpoint and debug it.
项目 + 属性,调试选项卡,向下滚动,勾选“启用非托管代码调试”复选框。现在您可以设置断点并调试它。
If your IDE doesn't support mixed mode debugging, you can attach a debugger using the technique outlined in this post.
如果您的IDE不支持混合模式调试,您可以将使用中概述的技术调试这个帖子。
回答by mcdon
Make sure your tessdata folder (C:\temp\tessdata) contains the english language data files. The files are: eng.DangAmbigs, eng.freq-dawg, eng.inttemp, eng.normproto, eng.pffmtable, eng.unicharset, eng.user-words, eng.word-dawg. download the files from tesseract downloads.The file to download is tesseract-2.00.eng.tar.gz.
确保您的 tessdata 文件夹 (C:\temp\tessdata) 包含英语数据文件。这些文件是:eng.DangAmbigs、eng.freq-dawg、eng.inttemp、eng.normproto、eng.pffmtable、eng.unicharset、eng.user-words、eng.word-dawg。从tesseract下载中下载文件。要下载的文件是 tesseract-2.00.eng.tar.gz。
回答by dkr88
For those attempting to use the Tessnet2 assembly for the Tesseract OCR engine in C# and who are running into the problem of the Tesseract.Init()
method causing your app to crash - I found one possible cause.
对于那些试图在 C# 中将 Tessnet2 程序集用于 Tesseract OCR 引擎以及Tesseract.Init()
遇到导致应用程序崩溃的方法问题的人- 我找到了一个可能的原因。
First, I'm assuming you have the files as follows:
首先,我假设你有如下文件:
bin\Debug\MyDotNetApp.exe
bin\Debug\tessdata\eng.DangAmbigs
bin\Debug\tessdata\eng.freq-dawg
bin\Debug\tessdata\eng.inttemp
bin\Debug\tessdata\eng.pffmtable
bin\Debug\tessdata\eng.unicharset
bin\Debug\tessdata\eng.user-words
bin\Debug\tessdata\eeng.word-dawg
And are using this for the initialization:
并使用它进行初始化:
using (var ocr = new tessnet2.Tesseract())
{
ocr.Init(null, "eng", false);
...
}
In theory that should work. For me it did work - but then it didn't all of a sudden... even though I didn't change anything that would affect it.
理论上应该可行。对我来说它确实有效 - 但它并没有突然之间......即使我没有改变任何会影响它的东西。
For me the fix was to search through the registry (using regedit) and remove all references to tesseract. There were some suspicious entries that I think may have been created when I installed the Tesseract 3.00 installer (tesseract-ocr-setup-3.00.exe).
对我来说,修复方法是搜索注册表(使用 regedit)并删除对 tesseract 的所有引用。在我安装 Tesseract 3.00 安装程序 (tesseract-ocr-setup-3.00.exe) 时,我认为可能已经创建了一些可疑条目。
When I deleted those entries and rebooted (I had tried rebooting before removing the reg entries, FYI), everything worked again.
当我删除这些条目并重新启动时(我曾尝试在删除 reg 条目之前重新启动,仅供参考),一切又恢复了。
Were the registry entries causing the problem? Who knows. But it did fix my problem.
是注册表项导致了问题吗?谁知道。但它确实解决了我的问题。
回答by B. Verhoeff
In my case the answer from dkr88 did the job, thanks a lot. I guess there some dependency corrupt when tesseract was installed as a standalone before. Furthermore, the OCR-quality seems to be better than with MODI although tiltcorrection os the latter is working under more extreme circumstances (vertical text).
就我而言,dkr88 的回答完成了这项工作,非常感谢。我猜当 tesseract 之前作为独立安装时会出现一些依赖关系。此外,OCR 质量似乎比 MODI 更好,尽管后者的倾斜校正在更极端的情况下(垂直文本)工作。
I'm pretty happy with tessnet2 now. There is only one drawback: I needed to change my app.config (as described on the internet) and added the following:
我现在对 tessnet2 很满意。只有一个缺点:我需要更改我的 app.config(如互联网上所述)并添加以下内容:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
回答by Nick
My problem is that I wasn't running the application with Administrator permissions.
我的问题是我没有使用管理员权限运行应用程序。
When I right clicked run as and chose Local Administrator it worked.
当我右键单击 run as 并选择 Local Administrator 时,它起作用了。
回答by Adam K Dean
For anyone still having a problem after all these, make sure if you're using tessnet2 that you download the correct language files.
对于在所有这些之后仍然有问题的任何人,请确保您使用的是 tessnet2 下载正确的语言文件。
You want English language data for Tesseract (2.00 and up)and not the English language data for Tesseract 3.01version. I hope this saves you a few hours! :)
您需要Tesseract(2.00 及更高版本)的英语语言数据,而不是Tesseract 3.01版本的英语语言数据。我希望这可以为您节省几个小时!:)
回答by Palanikumar
In my case, I did the below changes to get it work :)
就我而言,我做了以下更改以使其正常工作:)
- Downloaded https://tesseract-ocr.googlecode.com/files/tesseract-2.00.eng.tar.gz
- Pasted tessdatafolder to my Debug folder
- And did the following code changes
- 下载 https://tesseract-ocr.googlecode.com/files/tesseract-2.00.eng.tar.gz
- 将tessdata文件夹粘贴到我的 Debug 文件夹
- 并做了以下代码更改
ocr.Init("D:\MyApplication\MyApplication\Debug", "eng", false);
ocr.Init("D:\MyApplication\MyApplication\Debug", "eng", false);
to
到
ocr.Init(null, "eng", false);
ocr.Init(null, "eng", false);
回答by JBAkroyd
In my case I set the tessdata files to copy always, and then it didn't crash on the init line.
在我的情况下,我将 tessdata 文件设置为始终复制,然后它没有在 init 行崩溃。