【问题标题】:c# generate hocr file using charlesw tesseractc# 使用charlesw tesseract生成hocr文件
【发布时间】:2016-10-03 01:54:03
【问题描述】:

如何使用 tesseract 包装器 here 生成 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());
            }

【问题讨论】:

    标签: c# tesseract hocr


    【解决方案1】:

    string hocrText = page.GetHOCRText(pageNum - 1);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多