作者:dsafdasdfddsa_459 | 来源:互联网 | 2022-12-11 09:43
我正在使用tesseract进行OCR。我能够使应用程序正常工作并获得输出。在这里,我试图从发票中提取数据并获取提取的数据。但是输入中单词之间的间距在输出文件中必须相似。我现在正在获取每个单词和坐标。我需要根据坐标导出到文本文件
代码示例:
using (var engine = new TesseractEngine(Server.MapPath(@"~/tessdata"), "eng", EngineMode.Default))
{
engine.DefaultPageSegMode = PageSegMode.AutoOsd;
// have to load Pix via a bitmap since Pix doesn't support loading a stream.
using (var image = new System.Drawing.Bitmap(imageFile.PostedFile.InputStream))
{
Bitmap bmp = Resize(image, 1920, 1080);
using (var pix = PixConverter.ToPix(image))
{
using (var page = engine.Process(pix))
{
using (var iter = page.GetIterator())
{
iter.Begin();
do
{
Rect symbolBounds;
string path = Server.MapPath("~/Output/data.txt");
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out symbolBounds))
{
// do whatever you want with bounding box for the symbol
var curText = iter.GetText(PageIteratorLevel.Word);
//WriteToTextFile(curText, symbolBounds, path);
resultText.InnerText += curText;
// Your code here, 'rect' should containt the location of the text, 'curText' contains the actual text itself
}
} while (iter.Next(PageIteratorLevel.Word));
}
meanConfidenceLabel.InnerText = String.Format("{0:P}", page.GetMeanConfidence());
}
}
}
}
这是显示错误间距的输入和输出示例。