How to Get C# OCR Read Confidence with IronOCR
IronOCR's read confidence indicates how certain the OCR system is about recognized text accuracy, with values from 0 to 100 where higher scores mean greater reliability—access it via the Confidence property on any OcrResult object.
Read confidence in OCR (Optical Character Recognition) refers to the level of certainty or reliability that the OCR system assigns to the accuracy of the text it has recognized in an image or document. It is a measure of how confident the OCR system is that the recognized text is correct. This metric becomes particularly important when processing scanned documents, photos, or any images where text quality might vary.
A high confidence score indicates a high degree of certainty that the recognition is accurate, while a low confidence score suggests that the recognition may be less reliable. Understanding these confidence levels helps developers implement appropriate validation logic and error handling in their applications.
Quickstart: Get OCR Read Confidence in One Line
Use IronTesseract's Read method with an image file path, then access the Confidence property on the returned OcrResult to see how certain IronOCR is about its text recognition. It's a simple, reliable way to start evaluating OCR output accuracy.
Get started making PDFs with NuGet now:
Install IronOCR with NuGet Package Manager
Copy and run this code snippet.
double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence;Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download a C# library to access read confidence
- Prepare the targeted image and PDF document
- Access the `Confidence` property of the OCR result
- Retrieve the confidence of pages, paragraphs, lines, words, and characters
- Check the `Choices` property for alternative word choices
How Do I Get Read Confidence in C#?
After performing OCR on the input image, the confidence level of the text is stored in the Confidence property. Utilize the 'using' statement to automatically dispose of objects after use. Add documents such as images and PDFs with the OcrImageInput and OcrPdfInput classes, respectively. The Read method will return an OcrResult object that allows access to the Confidence property.
:path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-get-confidence.csusing 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;The confidence value returned ranges from 0 to 100, where:
- 90-100: Excellent confidence - Text is highly reliable
- 80-89: Good confidence - Text is generally accurate with minor uncertainties
- 70-79: Moderate confidence - Text may contain some errors
- Below 70: Low confidence - Text should be reviewed or reprocessed
How Can I Get Confidence at Different Levels?
Not only can you retrieve the confidence level of the entire document, but you can also access the confidence levels of each page, paragraph, line, word, and character. Furthermore, you can obtain the confidence of a block, which represents a collection of one or more paragraphs located closely together.
: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;Practical Example: Filtering by Confidence
When processing documents with varying quality, such as low-quality scans, you can use confidence scores to filter results:
using IronOcr;
using System.Linq;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Configure for better accuracy
ocrTesseract.Configuration.ReadBarCodes = false;
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd;
// Add image
using var imageInput = new OcrImageInput("invoice.png");
// Apply filters to improve quality
imageInput.Deskew();
imageInput.DeNoise();
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Filter words with confidence above 85%
var highConfidenceWords = ocrResult.Words
.Where(word => word.Confidence >= 85)
.Select(word => word.Text)
.ToList();
// Process only high-confidence text
string reliableText = string.Join(" ", highConfidenceWords);
Console.WriteLine($"High confidence text: {reliableText}");
// Flag low-confidence words for manual review
var lowConfidenceWords = ocrResult.Words
.Where(word => word.Confidence < 85)
.Select(word => new { word.Text, word.Confidence })
.ToList();
foreach (var word in lowConfidenceWords)
{
Console.WriteLine($"Review needed: '{word.Text}' (Confidence: {word.Confidence:F2}%)");
}using IronOcr;
using System.Linq;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Configure for better accuracy
ocrTesseract.Configuration.ReadBarCodes = false;
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd;
// Add image
using var imageInput = new OcrImageInput("invoice.png");
// Apply filters to improve quality
imageInput.Deskew();
imageInput.DeNoise();
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Filter words with confidence above 85%
var highConfidenceWords = ocrResult.Words
.Where(word => word.Confidence >= 85)
.Select(word => word.Text)
.ToList();
// Process only high-confidence text
string reliableText = string.Join(" ", highConfidenceWords);
Console.WriteLine($"High confidence text: {reliableText}");
// Flag low-confidence words for manual review
var lowConfidenceWords = ocrResult.Words
.Where(word => word.Confidence < 85)
.Select(word => new { word.Text, word.Confidence })
.ToList();
foreach (var word in lowConfidenceWords)
{
Console.WriteLine($"Review needed: '{word.Text}' (Confidence: {word.Confidence:F2}%)");
}What Are Character Choices in OCR?
Apart from the confidence level, there is another interesting property called Choices. Choices contain a list of alternative word choices and their statistical relevance. This information allows the user to access other possible characters. This feature is particularly useful when working with multiple languages or specialized fonts.
:path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-get-choices.csusing 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;How Do Alternative Character Choices Help?
Alternative character choices provide several benefits:
- Ambiguity Resolution: When characters like 'O' and '0', or 'l' and '1' are confused
- Font Variations: Different interpretations for stylized or decorative fonts
- Quality Issues: Multiple possibilities when dealing with degraded text
- Language Context: Alternative interpretations based on language rules

Working with Character Choices
Here's a comprehensive example demonstrating how to use character choices for improved accuracy:
using IronOcr;
using System;
using System.Linq;
using static IronOcr.OcrResult;
// Configure IronTesseract for detailed results
IronTesseract ocrTesseract = new IronTesseract();
// Process image with potential ambiguities
using var imageInput = new OcrImageInput("ambiguous_text.png");
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Analyze character choices for each word
foreach (var word in ocrResult.Words)
{
Console.WriteLine($"\nWord: '{word.Text}' (Confidence: {word.Confidence:F2}%)");
// Check each character in the word
foreach (var character in word.Characters)
{
if (character.Choices != null && character.Choices.Length > 1)
{
Console.WriteLine($" Character '{character.Text}' has alternatives:");
// Display all choices sorted by confidence
foreach (var choice in character.Choices.OrderByDescending(c => c.Confidence))
{
Console.WriteLine($" - '{choice.Text}': {choice.Confidence:F2}%");
}
}
}
}using IronOcr;
using System;
using System.Linq;
using static IronOcr.OcrResult;
// Configure IronTesseract for detailed results
IronTesseract ocrTesseract = new IronTesseract();
// Process image with potential ambiguities
using var imageInput = new OcrImageInput("ambiguous_text.png");
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Analyze character choices for each word
foreach (var word in ocrResult.Words)
{
Console.WriteLine($"\nWord: '{word.Text}' (Confidence: {word.Confidence:F2}%)");
// Check each character in the word
foreach (var character in word.Characters)
{
if (character.Choices != null && character.Choices.Length > 1)
{
Console.WriteLine($" Character '{character.Text}' has alternatives:");
// Display all choices sorted by confidence
foreach (var choice in character.Choices.OrderByDescending(c => c.Confidence))
{
Console.WriteLine($" - '{choice.Text}': {choice.Confidence:F2}%");
}
}
}
}Advanced Confidence Strategies
When working with specialized documents like passports, license plates, or MICR cheques, confidence scores become crucial for validation:
using IronOcr;
public class DocumentValidator
{
private readonly IronTesseract ocr = new IronTesseract();
public bool ValidatePassportNumber(string imagePath, double minConfidence = 95.0)
{
using var input = new OcrImageInput(imagePath);
// Configure for passport reading
ocr.Configuration.ReadBarCodes = true;
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine;
// Apply preprocessing
input.Deskew();
input.Scale(200); // Upscale for better accuracy
var result = ocr.Read(input);
// Find passport number pattern
var passportLine = result.Lines
.Where(line => line.Text.Contains("P<") || IsPassportNumberFormat(line.Text))
.FirstOrDefault();
if (passportLine != null)
{
Console.WriteLine($"Passport line found: {passportLine.Text}");
Console.WriteLine($"Confidence: {passportLine.Confidence:F2}%");
// Only accept if confidence meets threshold
return passportLine.Confidence >= minConfidence;
}
return false;
}
private bool IsPassportNumberFormat(string text)
{
// Simple passport number validation
return System.Text.RegularExpressions.Regex.IsMatch(text, @"^[A-Z]\d{7,9}$");
}
}using IronOcr;
public class DocumentValidator
{
private readonly IronTesseract ocr = new IronTesseract();
public bool ValidatePassportNumber(string imagePath, double minConfidence = 95.0)
{
using var input = new OcrImageInput(imagePath);
// Configure for passport reading
ocr.Configuration.ReadBarCodes = true;
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine;
// Apply preprocessing
input.Deskew();
input.Scale(200); // Upscale for better accuracy
var result = ocr.Read(input);
// Find passport number pattern
var passportLine = result.Lines
.Where(line => line.Text.Contains("P<") || IsPassportNumberFormat(line.Text))
.FirstOrDefault();
if (passportLine != null)
{
Console.WriteLine($"Passport line found: {passportLine.Text}");
Console.WriteLine($"Confidence: {passportLine.Confidence:F2}%");
// Only accept if confidence meets threshold
return passportLine.Confidence >= minConfidence;
}
return false;
}
private bool IsPassportNumberFormat(string text)
{
// Simple passport number validation
return System.Text.RegularExpressions.Regex.IsMatch(text, @"^[A-Z]\d{7,9}$");
}
}Optimizing for Better Confidence
To achieve higher confidence scores, consider using image filters and preprocessing techniques:
using IronOcr;
// Create an optimized OCR workflow
IronTesseract ocr = new IronTesseract();
using var input = new OcrImageInput("low_quality_scan.jpg");
// Apply multiple filters to improve confidence
input.Deskew(); // Correct rotation
input.DeNoise(); // Remove noise
input.Sharpen(); // Enhance edges
input.Dilate(); // Thicken text
input.Scale(150); // Upscale for clarity
// Configure for accuracy over speed
ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
ocr.Configuration.EngineMode = TesseractEngineMode.TesseractOnly;
var result = ocr.Read(input);
Console.WriteLine($"Document confidence: {result.Confidence:F2}%");
// Generate confidence report
var confidenceReport = result.Pages
.Select((page, index) => new
{
PageNumber = index + 1,
Confidence = page.Confidence,
WordCount = page.Words.Length,
LowConfidenceWords = page.Words.Count(w => w.Confidence < 80)
});
foreach (var page in confidenceReport)
{
Console.WriteLine($"Page {page.PageNumber}: {page.Confidence:F2}% confidence");
Console.WriteLine($" Total words: {page.WordCount}");
Console.WriteLine($" Low confidence words: {page.LowConfidenceWords}");
}using IronOcr;
// Create an optimized OCR workflow
IronTesseract ocr = new IronTesseract();
using var input = new OcrImageInput("low_quality_scan.jpg");
// Apply multiple filters to improve confidence
input.Deskew(); // Correct rotation
input.DeNoise(); // Remove noise
input.Sharpen(); // Enhance edges
input.Dilate(); // Thicken text
input.Scale(150); // Upscale for clarity
// Configure for accuracy over speed
ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
ocr.Configuration.EngineMode = TesseractEngineMode.TesseractOnly;
var result = ocr.Read(input);
Console.WriteLine($"Document confidence: {result.Confidence:F2}%");
// Generate confidence report
var confidenceReport = result.Pages
.Select((page, index) => new
{
PageNumber = index + 1,
Confidence = page.Confidence,
WordCount = page.Words.Length,
LowConfidenceWords = page.Words.Count(w => w.Confidence < 80)
});
foreach (var page in confidenceReport)
{
Console.WriteLine($"Page {page.PageNumber}: {page.Confidence:F2}% confidence");
Console.WriteLine($" Total words: {page.WordCount}");
Console.WriteLine($" Low confidence words: {page.LowConfidenceWords}");
}Summary
Understanding and utilizing OCR confidence scores is essential for building robust document processing applications. By leveraging IronOCR's confidence properties and character choices, developers can implement intelligent validation, error handling, and quality assurance mechanisms in their OCR workflows. Whether you're processing screenshots, tables, or specialized documents, confidence scores provide the metrics needed to ensure accurate text extraction.
Frequently Asked Questions
What is OCR confidence and why is it important?
OCR confidence is a measure from 0 to 100 indicating how certain the OCR system is about text recognition accuracy. IronOCR provides this metric through the Confidence property on any OcrResult object, helping developers assess the reliability of recognized text, especially when processing scanned documents, photos, or images with varying text quality.
How do I quickly check OCR confidence in C#?
With IronOCR, you can get OCR confidence in just one line of code: double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence; This returns a confidence score between 0-100 indicating how certain IronOCR is about its text recognition.
What do different confidence score ranges mean?
IronOCR confidence scores indicate: 90-100 (Excellent) means text is highly reliable; 80-89 (Good) means text is generally accurate with minor uncertainties; 70-79 (Moderate) means text may contain some errors; Below 70 (Low) means text should be reviewed or reprocessed.
How do I access confidence levels for different text elements?
IronOCR allows you to retrieve confidence levels at multiple granularities - pages, paragraphs, lines, words, and individual characters. After performing OCR, you can access the Confidence property at each level through the OcrResult object structure.
Can I get alternative word suggestions with confidence scores?
Yes, IronOCR provides a Choices property that offers alternative word choices along with their confidence scores. This feature helps when the OCR engine identifies multiple possible interpretations of the same text, allowing you to implement smart validation logic.
How do I implement confidence-based validation in my application?
After using IronOCR's Read method, check the Confidence property of the OcrResult. Implement conditional logic based on confidence thresholds - for example, automatically accept results above 90, flag results between 70-90 for review, and reprocess or manually verify results below 70.







