如何在 C# 中使用 Tesseract OCR 信心值 | IronOCR

如何使用 IronOCR 提升 C# OCR 读取的信心

This article was translated from English: Does it need improvement?
Translated
View the article in English

OCR(光学字符识别)的读取置信度是指 OCR 系统对图像或文档中识别出的文本的准确性所赋予的确定性或可靠性级别。 它是衡量 OCR 系统对识别文本正确性的信心程度的指标。

置信度得分越高,表示识别结果的准确性越有把握;而置信度得分越低,则表示识别结果的可靠性可能较低。

快速入门:一行代码获取 OCR 读取置信度

使用 IronTesseract 的Read方法和图像文件路径,然后访问返回的OcrResultConfidence属性,以查看 IronOCR 对其文本识别的确定性。 这是一种简单可靠的评估 OCR 输出准确性的方法。

Nuget Icon立即开始使用 NuGet 创建 PDF 文件:

  1. 使用 NuGet 包管理器安装 IronOCR

    PM > Install-Package IronOcr

  2. 复制并运行这段代码。

    double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence;
  3. 部署到您的生产环境中进行测试

    立即开始在您的项目中使用 IronOCR,免费试用!
    arrow pointer


获取阅读信心示例

对输入图像执行 OCR 后,文本置信度存储在Confidence属性中。 使用"using"语句可以在使用后自动释放对象。 分别使用OcrImageInputOcrPdfInput类添加图像和 PDF 等文档。 Read 方法将返回一个 OcrResult 对象,以便访问 Confidence 属性。

:path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-get-confidence.cs
using IronOcr;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sample.tiff");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Get confidence level
double confidence = ocrResult.Confidence;
Imports IronOcr

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Add image
Private imageInput = New OcrImageInput("sample.tiff")
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)

' Get confidence level
Private confidence As Double = ocrResult.Confidence
$vbLabelText   $csharpLabel

提升不同层次的阅读自信

您不仅可以获取整个文档的置信度,还可以访问每一页、段落、行、单词和字符的置信度。 此外,您还可以获得块的置信度,该块表示一个或多个紧密相邻的段落的集合。

:path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-confidence-level.cs
// Get page confidence level
double pageConfidence = ocrResult.Pages[0].Confidence;

// Get paragraph confidence level
double paragraphConfidence = ocrResult.Paragraphs[0].Confidence;

// Get line confidence level
double lineConfidence = ocrResult.Lines[0].Confidence;

// Get word confidence level
double wordConfidence = ocrResult.Words[0].Confidence;

// Get character confidence level
double characterConfidence = ocrResult.Characters[0].Confidence;

// Get block confidence level
double blockConfidence = ocrResult.Blocks[0].Confidence;
' Get page confidence level
Dim pageConfidence As Double = ocrResult.Pages(0).Confidence

' Get paragraph confidence level
Dim paragraphConfidence As Double = ocrResult.Paragraphs(0).Confidence

' Get line confidence level
Dim lineConfidence As Double = ocrResult.Lines(0).Confidence

' Get word confidence level
Dim wordConfidence As Double = ocrResult.Words(0).Confidence

' Get character confidence level
Dim characterConfidence As Double = ocrResult.Characters(0).Confidence

' Get block confidence level
Dim blockConfidence As Double = ocrResult.Blocks(0).Confidence
$vbLabelText   $csharpLabel

获取角色选择

除了置信水平之外,还有另一个有趣的属性叫做选择。 选项中包含备选词语列表及其统计相关性。 此信息允许用户访问其他可能的角色。

:path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-get-choices.cs
using IronOcr;
using static IronOcr.OcrResult;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("Potter.tiff");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Get choices
Choice[] choices = ocrResult.Characters[0].Choices;
Imports IronOcr
Imports IronOcr.OcrResult

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Add image
Private imageInput = New OcrImageInput("Potter.tiff")
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)

' Get choices
Private choices() As Choice = ocrResult.Characters(0).Choices
$vbLabelText   $csharpLabel

检索信息

选择

常见问题解答

在OCR中读取信心是什么意思?

OCR中的读取信心是指OCR系统对其识别文本的准确性分配的确定性或可靠性等级。高分数表示可靠的文本识别,而低分数则表明可能存在不准确。

如何开始使用C#库获取OCR读取信心?

首先从NuGet下载IronOCR库。准备处理您的图像或PDF文档,并使用Read方法从OcrResult对象中访问Confidence属性。

如何在C#中检索识别文本的信心水平?

要检索识别文本的信心水平,请使用IronOCR的Read方法,该方法返回一个OcrResult对象。此对象包括一个Confidence属性,指示文本的准确性水平。

我可以检查文档不同部分的信心水平吗?

是的,IronOCR允许您检查文档各个部分的信心水平,包括页面、段落、行、单词和字符。这提供了对OCR过程的详细准确性评估。

OCR中的字符选择是什么?

OCR中的字符选择提供了替代单词选择及其统计相关性列表。此功能帮助用户访问OCR系统识别的其他可能字符,提供对识别过程的额外见解。

在C# OCR库中如何使用信心属性?

C# OCR库中的Confidence属性指示识别文本的准确性水平。它提供了表示OCR系统对识别准确性确定性的数值评分。

在C# OCR库中是否可以访问块级信心?

是的,可以使用IronOCR访问块级信心。一个块代表一组密集排列的段落,其信心水平可以被检查以评估这一水平的文本识别准确性。

OCR中Choices属性的用途是什么?

Choices 属性提供替代的单词选择及其置信度得分。这帮助用户理解 OCR 系统提供的其他潜在文本解释,从而增强对识别文本的评估。

如何在C#中实现具有信心水平的OCR?

通过使用IronOCR库在C#中实现具有信心水平的OCR。设置您的环境,准备输入文档,并利用Read方法获取OcrResult对象,从中可以访问Confidence属性。

要评估使用C# OCR库的读取信心,我应该遵循哪些步骤?

要评估读取信心,请下载IronOCR库,为OCR处理准备文档,使用Read方法获取OcrResult,并访问Confidence属性以评估识别文本的准确性。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

审核者
Jeff Fritz
Jeffrey T. Fritz
首席项目经理 - .NET 社区团队
Jeff 也是 .NET 和 Visual Studio 团队的首席项目经理。他是 .NET Conf 虚拟会议系列的执行制片人,并主持“Fritz and Friends”直播节目,每周两次与观众一起谈论技术并编写代码。Jeff 撰写研讨会、演示文稿并计划包括 Microsoft Build、Microsoft Ignite、.NET Conf 和 Microsoft MVP 峰会在内的最大型微软开发者活动的内容。
准备开始了吗?
Nuget 下载 5,167,857 | Version: 2025.11 刚刚发布