/* :path=/static-assets/ocr/content-code-examples/how-to/input-images-read.cs */using IronOcr;// Instantiate IronTesseractIronTesseract ocrTesseract = new IronTesseract();// Add imageusing var imageInput = new OcrImageInput("Potter.png");// Perform OCROcrResult ocrResult = ocrTesseract.Read(imageInput);// Display the extracted textConsole.WriteLine(ocrResult.Text);// Get confidence leveldouble confidence = ocrResult.Confidence;Console.WriteLine($"Confidence: {confidence}%");
/* :path=/static-assets/ocr/content-code-examples/how-to/input-images-read.cs */
using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("Potter.png");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Display the extracted text
Console.WriteLine(ocrResult.Text);
// Get confidence level
double confidence = ocrResult.Confidence;
Console.WriteLine($"Confidence: {confidence}%");
ImportsIronOcr' Instantiate IronTesseractDim ocrTesseract As New IronTesseract()' Add imageUsing imageInput As New OcrImageInput("Potter.png") ' Perform OCR Dim ocrResult AsOcrResult = ocrTesseract.Read(imageInput) ' Display the extracted textConsole.WriteLine(ocrResult.Text) ' Get confidence level Dim confidence AsDouble = ocrResult.ConfidenceConsole.WriteLine($"Confidence: {confidence}%")EndUsing
Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("Potter.png")
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Display the extracted text
Console.WriteLine(ocrResult.Text)
' Get confidence level
Dim confidence As Double = ocrResult.Confidence
Console.WriteLine($"Confidence: {confidence}%")
End Using
using IronOcr;using System.IO;// Instantiate IronTesseractIronTesseract ocrTesseract = new IronTesseract();// Read byte from filebyte[] data = File.ReadAllBytes("Potter.tiff");// Import image byteusing var imageInput = new OcrImageInput(data);// Perform OCROcrResult ocrResult = ocrTesseract.Read(imageInput);
using IronOcr;
using System.IO;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Read byte from file
byte[] data = File.ReadAllBytes("Potter.tiff");
// Import image byte
using var imageInput = new OcrImageInput(data);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
ImportsIronOcrImportsSystem.IO' Instantiate IronTesseractDim ocrTesseract As New IronTesseract()' Read byte from fileDim data AsByte() = File.ReadAllBytes("Potter.tiff")' Import image byteUsing imageInput As New OcrImageInput(data) ' Perform OCR Dim ocrResult AsOcrResult = ocrTesseract.Read(imageInput)EndUsing
Imports IronOcr
Imports System.IO
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Read byte from file
Dim data As Byte() = File.ReadAllBytes("Potter.tiff")
' Import image byte
Using imageInput As New OcrImageInput(data)
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
End Using
using IronOcr;using IronSoftware.Drawing;using System.IO;// Method 1: From URLvar imageFromUrl = AnyBitmap.FromUri("https://example.com/document.jpg");using var urlInput = new OcrImageInput(imageFromUrl);// Method 2: From Streamusing var fileStream = File.OpenRead("document.png");using var streamInput = new OcrImageInput(fileStream);// Method 3: From System.Drawing (with IronSoftware.Drawing)var bitmap = AnyBitmap.FromFile("scan.bmp");using var bitmapInput = new OcrImageInput(bitmap);// Process any of these inputsIronTesseract ocr = new IronTesseract();OcrResult result = ocr.Read(bitmapInput);
using IronOcr;
using IronSoftware.Drawing;
using System.IO;
// Method 1: From URL
var imageFromUrl = AnyBitmap.FromUri("https://example.com/document.jpg");
using var urlInput = new OcrImageInput(imageFromUrl);
// Method 2: From Stream
using var fileStream = File.OpenRead("document.png");
using var streamInput = new OcrImageInput(fileStream);
// Method 3: From System.Drawing (with IronSoftware.Drawing)
var bitmap = AnyBitmap.FromFile("scan.bmp");
using var bitmapInput = new OcrImageInput(bitmap);
// Process any of these inputs
IronTesseract ocr = new IronTesseract();
OcrResult result = ocr.Read(bitmapInput);
ImportsIronOcrImportsIronSoftware.DrawingImportsSystem.IO' Method 1: From URLDim imageFromUrl = AnyBitmap.FromUri("https://example.com/document.jpg")Using urlInput As New OcrImageInput(imageFromUrl) ' Method 2: From StreamUsing fileStream AsFileStream = File.OpenRead("document.png")Using streamInput As New OcrImageInput(fileStream) ' Method 3: From System.Drawing (with IronSoftware.Drawing) Dim bitmap = AnyBitmap.FromFile("scan.bmp")Using bitmapInput As New OcrImageInput(bitmap) ' Process any of these inputs Dim ocr As New IronTesseract() Dim result AsOcrResult = ocr.Read(bitmapInput)EndUsingEndUsingEndUsingEndUsing
Imports IronOcr
Imports IronSoftware.Drawing
Imports System.IO
' Method 1: From URL
Dim imageFromUrl = AnyBitmap.FromUri("https://example.com/document.jpg")
Using urlInput As New OcrImageInput(imageFromUrl)
' Method 2: From Stream
Using fileStream As FileStream = File.OpenRead("document.png")
Using streamInput As New OcrImageInput(fileStream)
' Method 3: From System.Drawing (with IronSoftware.Drawing)
Dim bitmap = AnyBitmap.FromFile("scan.bmp")
Using bitmapInput As New OcrImageInput(bitmap)
' Process any of these inputs
Dim ocr As New IronTesseract()
Dim result As OcrResult = ocr.Read(bitmapInput)
End Using
End Using
End Using
End Using
using IronOcr;using IronSoftware.Drawing;using System;// Instantiate IronTesseractIronTesseract ocrTesseract = new IronTesseract();// Specify crop regionRectangle scanRegion = new Rectangle(800, 200, 900, 400);// Add imageusing var imageInput = new OcrImageInput("Potter.tiff", ContentArea: scanRegion);// Perform OCROcrResult ocrResult = ocrTesseract.Read(imageInput);// Output the result to consoleConsole.WriteLine(ocrResult.Text);
using IronOcr;
using IronSoftware.Drawing;
using System;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Specify crop region
Rectangle scanRegion = new Rectangle(800, 200, 900, 400);
// Add image
using var imageInput = new OcrImageInput("Potter.tiff", ContentArea: scanRegion);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Output the result to console
Console.WriteLine(ocrResult.Text);
ImportsIronOcrImportsIronSoftware.DrawingImportsSystem' Instantiate IronTesseractDim ocrTesseract As New IronTesseract()' Specify crop regionDim scanRegion As New Rectangle(800, 200, 900, 400)' Add imageUsing imageInput As New OcrImageInput("Potter.tiff", ContentArea:=scanRegion) ' Perform OCR Dim ocrResult AsOcrResult = ocrTesseract.Read(imageInput) ' Output the result to consoleConsole.WriteLine(ocrResult.Text)EndUsing
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Specify crop region
Dim scanRegion As New Rectangle(800, 200, 900, 400)
' Add image
Using imageInput As New OcrImageInput("Potter.tiff", ContentArea:=scanRegion)
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Output the result to console
Console.WriteLine(ocrResult.Text)
End Using
using IronOcr;IronTesseract ocr = new IronTesseract();using var input = new OcrImageInput("low-quality-scan.jpg");// Apply image enhancement filtersinput.Deskew(); // Correct image rotationinput.DeNoise(); // Remove background noiseinput.Binarize(); // Convert to black and whiteinput.EnhanceResolution(300); // Adjust DPI for better accuracy// Configure for better accuracyocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";ocr.Language = OcrLanguage.English;OcrResult result = ocr.Read(input);
using IronOcr;
IronTesseract ocr = new IronTesseract();
using var input = new OcrImageInput("low-quality-scan.jpg");
// Apply image enhancement filters
input.Deskew(); // Correct image rotation
input.DeNoise(); // Remove background noise
input.Binarize(); // Convert to black and white
input.EnhanceResolution(300); // Adjust DPI for better accuracy
// Configure for better accuracy
ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
ocr.Language = OcrLanguage.English;
OcrResult result = ocr.Read(input);
How can specifying a scan region improve OCR performance?
Specifying a scan region limits OCR processing to relevant parts of the image, reducing computational overhead and processing time, while enhancing accuracy by focusing only on target text areas.
What memory management practices should be followed when using IronOCR?
Use 'using' statements for resource disposal when working with large images, implement a queue system for batch processing, and monitor memory usage to handle multiple documents simultaneously.
Why should I use parallel processing for OCR tasks?
Parallel processing is ideal for handling multiple independent image files, allowing you to maximize CPU usage and speed up batch operations while managing memory constraints.