gpt4 book ai didi

c# - Tesseract Init() 方法 C3

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:59 24 4
gpt4 key购买 nike

我在 C# .net 4.5 中使用 Tesseract 2每当代码到达 OCR.InIt() 方法时,它就会退出代码并且程序停止执行。即使是 Catch block 也不保存代码。请让我知道如何检查问题。

Bitmap image = new Bitmap(ofd_OpenPhoto.FileName);
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.Init("C:\\tessnet2\\tesseract-ocr\\tessdata", "eng", false);

请告诉我,如何使用 Init() 方法,我应该删除 null 吗?

private void btn_Browse_Click(object sender, EventArgs e)
{
ofd_OpenPhoto.Multiselect = false;
ofd_OpenPhoto.RestoreDirectory = true;
ofd_OpenPhoto.SupportMultiDottedExtensions = false;
ofd_OpenPhoto.FileName = "";
ofd_OpenPhoto.Title = "Select Photo";
ofd_OpenPhoto.Filter = "Photo Files (*.jpg)|*.jpg";

DialogResult result = ofd_OpenPhoto.ShowDialog();

if (result == System.Windows.Forms.DialogResult.OK)
{
string file_name;
if (ofd_OpenPhoto.FileName != null)
{
try
{
file_name = ofd_OpenPhoto.FileName.Substring(ofd_OpenPhoto.FileName.LastIndexOf("\\") + 1);
txt_PhotoPath.Text = file_name.Substring(0, file_name.LastIndexOf("."));

Emgu.CV.Image<Bgr, Byte> img_o = new Emgu.CV.Image<Bgr, byte>(ofd_OpenPhoto.FileName);
pb_PhotoViewer_O.Image = img_o.ToBitmap();
if (pb_PhotoViewer_O.Image != null)
{
try
{
Bitmap image = new Bitmap(ofd_OpenPhoto.FileName);
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
ocr.Init(@"C:\\Program Files (x86)\\Tesseract-OCR", "eng", false);
List<tessnet2.Word> result1 = ocr.DoOCR(image, Rectangle.Empty);
txt_ExtractedNumber.Text = result1.ToString();
}
catch (Exception ex)
{

}
}
}
catch (Exception ex)
{
//e.Message();
}
}
}
}

这是我的代码。谢谢。

最佳答案

如果你写ocr.Init("C:\\tessnet2\\tesseract-ocr\\tessdata", "eng", false);然后在 C:\tessnet2\tesseract-ocr\tessdata 目录下你必须有下一个文件:

  • eng.DangAmbigs
  • eng.freq-dawg
  • eng.inttemp
  • eng.normproto
  • eng.pffmtable
  • eng.unicharset
  • eng.user-words
  • eng.word-dawg

您还必须检查是否删除了 Windows 系统环境变量 (TESSDATA_PREFIX)

关于c# - Tesseract Init() 方法 C3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20566474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com