如何在 HTML 文件中将结果保存为 hOCR
hOCR,即“基于HTML的OCR”,是一种用于以结构化方式表示光学字符识别(OCR)结果的文件格式。 HOCR 文件通常以 HTML(超文本标记语言)编写,提供了一种存储识别文本、布局信息以及图像或文档中每个识别字符坐标的方法。
IronOCR提供了一个解决方案,用于对文档执行光学字符识别,并将结果以HTML格式的hOCR导出。 它支持HTML文件和字符串。
开始使用IronOCR
立即在您的项目中开始使用IronOCR,并享受免费试用。
如何在 HTML 文件中将结果保存为 hOCR
将结果导出为hOCR示例
要将结果导出为 hOCR,用户首先必须通过将Configuration.RenderHocr属性设置为 true 来启用它。 从Read
方法获取OCR结果对象后,使用SaveAsHocrFile
方法将OCR结果导出为HTML。 此方法将输出一个HTML文件,其中包含输入文档的阅读结果。 下面的代码演示了如何使用以下示例 TIFF文件。
:path=/static-assets/ocr/content-code-examples/how-to/html-export-export-html.cs
using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Enable render as hOCR
ocrTesseract.Configuration.RenderHocr = true;
// Add image
using var imageInput = new OcrImageInput("Potter.tiff");
imageInput.Title = "Html Title";
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Export as HTML
ocrResult.SaveAsHocrFile("result.html");
Imports IronOcr
' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()
' Enable render as hOCR
ocrTesseract.Configuration.RenderHocr = True
' Add image
Dim imageInput = New OcrImageInput("Potter.tiff")
imageInput.Title = "Html Title"
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Export as HTML
ocrResult.SaveAsHocrFile("result.html")
将结果导出为HTML字符串
使用相同的TIFF样本图像,您可以利用SaveAsHocrString
方法将OCR结果导出为HTML字符串。 此方法将返回一个 HTML 字符串。
:path=/static-assets/ocr/content-code-examples/how-to/html-export-export-html-string.cs
// Export as HTML string
string hocr = ocrResult.SaveAsHocrString();
' Export as HTML string
Dim hocr As String = ocrResult.SaveAsHocrString()