c#使用charlesw tesseract生成hocr文件
本文关键字:hocr 文件 生成 tesseract 使用 charlesw | 更新日期: 2023-09-27 18:09:52
如何使用tesseract包装器生成hocr
目前,我需要动态地将tessdata的位置添加到环境变量中,并运行我的代码
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + @"'tesseract-3.05.00dev-win32-vc19'tesseract.exe";
string inputImg = @"00067.jpg";
string hocrLocation = @"00067";
string argsPdf = "'"" + inputImg + "'"" + " " + "'"" + hocrLocation + "'"" + " hocr ";
Console.WriteLine(argsPdf);
pProcess.StartInfo.Arguments = argsPdf;
pProcess.StartInfo.CreateNoWindow = false;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
Console.WriteLine("OUtput: " + strOutput);
pProcess.WaitForExit();
然后我找到了tesseract包装。如何使用包装器生成hocr文件?我找不到一个例子来做这件事。
这是当前的代码(从例子)我使用,但如何输出一个hocr文件?
var testImagePath = "./phototest.tif";
if (args.Length > 0)
{
testImagePath = args[0];
}
try
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
{
using (var img = Pix.LoadFromFile(testImagePath))
{
using (var page = engine.Process(img))
{
}
}
}
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
Console.WriteLine("Unexpected Error: " + e.Message);
Console.WriteLine("Details: ");
Console.WriteLine(e.ToString());
}
string hocrText = page.GetHOCRText(pageNum - 1);