使用charlesw tesseract生成hocr文件

时间:2021-07-18 08:57:40

how can i generate hocr using the tesseract wrapper here

如何使用tesseract包装器生成hocr ?

currently i need to dynamically add the location of the tessdata to the environment variables and run my code

目前,我需要动态地将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();

and then i found the tesseract wrapper. how can i generate an hocr file using the wrapper? i cant find an example how to do it.

然后我找到了tesseract包装器。如何使用包装器生成一个hocr文件?我找不到一个如何做这件事的例子。

this is the current code(from the example ) im using but how to output an hocr file?

这是当前正在使用的代码(来自示例),但是如何输出一个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());
            }

1 个解决方案

#1


0  

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

字符串hocrText =页面。GetHOCRText(pageNum - 1);

#1


0  

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

字符串hocrText =页面。GetHOCRText(pageNum - 1);