我正在使用带有c#.net 4.5的Tesseract 2 每当代码到达OCR.InIt()方法时,它就会出现代码,程序会停止执行。 即使是Catch块也不能保存代码。 请让我知道如何检查问题。
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();
}
}
}
}
这是我的代码。 谢谢。
答案 0 :(得分:1)
如果你写ocr.Init("C:\\tessnet2\\tesseract-ocr\\tessdata", "eng", false);
然后在 C:\ tessnet2 \ tesseract-ocr \ tessdata 目录中,你必须有下一个文件:
您还必须检查是否已删除Windows系统环境变量(TESSDATA_PREFIX)