我正在使用 Tessnet 作为 C# 包装器的 tesseract 引擎上运行 OCR。我已经获得了识别单词的图像坐标,我想使用这些坐标仅显示页面的那一部分。我不在乎此页面部分是否保存为单独的图像,或者它只是以某种方式突出显示 tif 图像的部分。
这是我当前的代码:
TextWriter tw = new StreamWriter(@"U:\user files\bwalker\ocrTesting.txt");
Bitmap image = new Bitmap(@"u:\user files\bwalker\2849257.tif");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,$-/#&=()\"':?"); // If digit only
ocr.Init(@"C:\Users\bwalker\Documents\Visual Studio 2010\Projects\tessnetWinForms\tessnetWinForms\bin\Release\", "eng", false); // To use correct tessdata
List<tessnet2.Word> result = ocr.DoOCR(image, System.Drawing.Rectangle.Empty);
string Results = "";
foreach (tessnet2.Word word in result)
{
Results += word.Confidence + ", " + word.Text + ", " +word.Top+", "+word.Bottom+", "+word.Left+", "+word.Right+"\n";
}
using (StreamWriter writer = new StreamWriter(@"U:\user files\bwalker\ocrTesting2.txt", true))
{
writer.WriteLine(Results);
writer.Close();
}
MessageBox.Show("Completed");
这是生成的 .txt 文件的一部分:
14, Due, 105, 136, 1886, 1962
89, Date, 105, 136, 1978, 2064
50, 06/16/2009, 105, 136, 2298, 2504