Tessnet2 协助
我需要建议。我正在尝试使用 Tessnet2 lib 来识别图像文本。
图像由一个包含五个字符(字符和数字)的字符串组成。
我从http://www.pixel-technology.com/freeware/tessnet2下载了lib /.
在我的项目中添加对此库的引用。
然后我下载了语言数据定义文件(来自 http://code .google.com/p/tesseract-ocr/downloads/list)并将其放入tessdata目录中。
数据定义文件与exe文件位于同一目录中。
这是我的代码:
try
{ //download image from server
System.Net.WebRequest request =
System.Net.WebRequest.Create(
textBox1.Text);
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream responseStream =
response.GetResponseStream();
Bitmap image = new Bitmap(responseStream);
pictureBox1.Image =image;
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789");
ocr.Init(@"C:\Users\Tan\Documents\Visual Studio 2010\Projects\TestProject\bin\Release", "eng", false); // To use correct tessdata
List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
foreach (tessnet2.Word word in result)
{
richTextBox1.Text = string.Format("{0} : {1}", word.Confidence, word.Text);
}
}
catch (System.Net.WebException)
{
MessageBox.Show("There was an error opening the image file."
+ "Check the URL");
}
问题是,如果我调用此代码,应用程序将关闭。我没有收到任何错误消息。我不明白为什么。 有人可以帮助我吗?谢谢。
I need advice. I am trying to use Tessnet2 lib to recognize text of image.
Image consist a string with five characters(chars and digit).
I downloaded lib from http://www.pixel-technology.com/freeware/tessnet2/.
Add refrence on this lib in my project.
Then I downloaded language data definition file (from http://code.google.com/p/tesseract-ocr/downloads/list)and put it in tessdata directory.
The data definition file is in same directory as exe file.
Here is my code:
try
{ //download image from server
System.Net.WebRequest request =
System.Net.WebRequest.Create(
textBox1.Text);
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream responseStream =
response.GetResponseStream();
Bitmap image = new Bitmap(responseStream);
pictureBox1.Image =image;
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789");
ocr.Init(@"C:\Users\Tan\Documents\Visual Studio 2010\Projects\TestProject\bin\Release", "eng", false); // To use correct tessdata
List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
foreach (tessnet2.Word word in result)
{
richTextBox1.Text = string.Format("{0} : {1}", word.Confidence, word.Text);
}
}
catch (System.Net.WebException)
{
MessageBox.Show("There was an error opening the image file."
+ "Check the URL");
}
Problem is, if I invoke this code, app is closed. I get nothing error message. I don’t why.
Can anybody help me? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你安装了 Tesseract 3 吗?
如果是这样,请将其卸载并删除名为 tessdata 的环境变量,然后重新启动。
Have you installed Tesseract 3 ?
If so uninstall it and remove the environment variable named something with tessdata, and restart.
我认为错误在 ocr.Init 行,请确保路径正确。还尝试传递 null,因为我记得它不需要路径,因为您始终必须将 tessdata 目录中的所有数据放在包含 exe 文件的同一文件夹中。
I think the error in ocr.Init line, be sure the path is correct. Also try to pass null as I remember it does not need the path because you always have to put all data in tessdata directory in the same folder which contains your exe file.
尝试在 Visual Studio 中使用“调试”解决方案配置来对抗“发布”解决方案配置。一些调试信息不包含在发布配置中。并射出这样的虫子。
Try to use Debug solution configuration in Visual Studio against Release solution configuration. Some debug information are not included in Release configuration. And shoots bugs like that.
问题出在你的 ocr.Init() 上。确保目录“C:\Users\Tan\Documents\Visual Studio 2010\Projects\TestProject\bin\Release”包含所需的文件:
eng.DangAmbigs
eng.freq-dawg
eng.inttemp
eng.normproto
eng.pffmtable
eng。 unicharset
eng.user-words
eng.word-dawg
The problem lies with your ocr.Init(). Make sure that directory "C:\Users\Tan\Documents\Visual Studio 2010\Projects\TestProject\bin\Release" contains the required files:
eng.DangAmbigs
eng.freq-dawg
eng.inttemp
eng.normproto
eng.pffmtable
eng.unicharset
eng.user-words
eng.word-dawg
如果有人仍然想知道在这种情况下该怎么做:
我遇到了同样的问题,我可以在 此链接 并将 tessdata 目录传递给 init 函数。 (主函数中有一个,OCR 类中有两个。)
上面提到的链接帮助了我,因为我必须下载 v2.00 语言文件而不是最新的 v3.0x ...
最好的问候
If someone still wants to know what to do in this case:
I had the same problem and i could fix it with help of this link and passing the tessdata directory to the init functions. (There is one in the main function and two in OCR class.)
The link mentioned above helped me as i had to download the v2.00 language files instead of the latest v3.0x ...
Best regards