using IronOcr;using IronSoftware.Drawing;// 1. Install IronOCR via NuGet: Install-Package IronOcrvar ocr = new IronTesseract();using var input = new OcrInput();// 2. Create a Rectangle with coordinatesvar region = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);// 3. Load image with regioninput.LoadImage("image.png", region);// 4. Extract textvar result = ocr.Read(input);Console.WriteLine(result.Text);
using IronOcr;
using IronSoftware.Drawing;
// 1. Install IronOCR via NuGet: Install-Package IronOcr
var ocr = new IronTesseract();
using var input = new OcrInput();
// 2. Create a Rectangle with coordinates
var region = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);
// 3. Load image with region
input.LoadImage("image.png", region);
// 4. Extract text
var result = ocr.Read(input);
Console.WriteLine(result.Text);
using IronOcr;using IronSoftware.Drawing;using System;var ocrTesseract = new IronTesseract();using var ocrInput = new OcrInput();// Define the specific region as a Rectangle// (x, y) is the top-left corner.varContentArea = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);ocrInput.LoadImage("region-input.png", ContentArea);var ocrResult = ocrTesseract.Read(ocrInput);// Print the extracted textConsole.WriteLine(ocrResult.Text);
using IronOcr;
using IronSoftware.Drawing;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define the specific region as a Rectangle
// (x, y) is the top-left corner.
var ContentArea = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);
ocrInput.LoadImage("region-input.png", ContentArea);
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text
Console.WriteLine(ocrResult.Text);
ImportsIronOcrImportsIronSoftware.DrawingImportsSystemDim ocrTesseract As New IronTesseract()Using ocrInput As New OcrInput() ' Define the specific region as a Rectangle ' (x, y) is the top-left corner. DimContentAreaAs New Rectangle(x:=215, y:=1250, width:=1335, height:=280) ocrInput.LoadImage("region-input.png", ContentArea) Dim ocrResult = ocrTesseract.Read(ocrInput) ' Print the extracted textConsole.WriteLine(ocrResult.Text)EndUsing
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
Dim ocrTesseract As New IronTesseract()
Using ocrInput As New OcrInput()
' Define the specific region as a Rectangle
' (x, y) is the top-left corner.
Dim ContentArea As New Rectangle(x:=215, y:=1250, width:=1335, height:=280)
ocrInput.LoadImage("region-input.png", ContentArea)
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Print the extracted text
Console.WriteLine(ocrResult.Text)
End Using
using IronOcr;using IronSoftware.Drawing;var ocr = new IronTesseract();// Define multiple regions for different form fieldsvar nameField = new Rectangle(x: 100, y: 200, width: 300, height: 50);var dateField = new Rectangle(x: 100, y: 300, width: 200, height: 50);var amountField = new Rectangle(x: 400, y: 500, width: 150, height: 50);// Load the same image with a separate OcrInput per regionOcrResult nameResult;using (var input = new OcrInput()){ input.LoadImage("form.png", nameField); nameResult = ocr.Read(input);}OcrResult dateResult;using (var input = new OcrInput()){ input.LoadImage("form.png", dateField); dateResult = ocr.Read(input);}OcrResult amountResult;using (var input = new OcrInput()){ input.LoadImage("form.png", amountField); amountResult = ocr.Read(input);}// Process each field separatelyConsole.WriteLine($"Name: {nameResult.Text}");Console.WriteLine($"Date: {dateResult.Text}");Console.WriteLine($"Amount: {amountResult.Text}");
using IronOcr;
using IronSoftware.Drawing;
var ocr = new IronTesseract();
// Define multiple regions for different form fields
var nameField = new Rectangle(x: 100, y: 200, width: 300, height: 50);
var dateField = new Rectangle(x: 100, y: 300, width: 200, height: 50);
var amountField = new Rectangle(x: 400, y: 500, width: 150, height: 50);
// Load the same image with a separate OcrInput per region
OcrResult nameResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", nameField);
nameResult = ocr.Read(input);
}
OcrResult dateResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", dateField);
dateResult = ocr.Read(input);
}
OcrResult amountResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", amountField);
amountResult = ocr.Read(input);
}
// Process each field separately
Console.WriteLine($"Name: {nameResult.Text}");
Console.WriteLine($"Date: {dateResult.Text}");
Console.WriteLine($"Amount: {amountResult.Text}");
using IronOcr;using IronSoftware.Drawing;var ocrTesseract = new IronTesseract();using var ocrInput = new OcrInput();// Define the specific rectangular area to scan within the image.// The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.varContentArea = new Rectangle(x: 4, y: 59, width: 365, height: 26);ocrInput.LoadImage("region-input.png", ContentArea);var ocrResult = ocrTesseract.Read(ocrInput);// Draws the rectangle from above in a blue bounding box on the image for visualization.ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png");
using IronOcr;
using IronSoftware.Drawing;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define the specific rectangular area to scan within the image.
// The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.
var ContentArea = new Rectangle(x: 4, y: 59, width: 365, height: 26);
ocrInput.LoadImage("region-input.png", ContentArea);
var ocrResult = ocrTesseract.Read(ocrInput);
// Draws the rectangle from above in a blue bounding box on the image for visualization.
ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png");
ImportsIronOcrImportsIronSoftware.DrawingDim ocrTesseract = New IronTesseract()Using ocrInput As New OcrInput() ' Define the specific rectangular area to scan within the image. ' The coordinates are in pixels: (x, y) is the top-left corner of the rectangle. DimContentAreaAs New Rectangle(x:=4, y:=59, width:=365, height:=26) ocrInput.LoadImage("region-input.png", ContentArea) Dim ocrResult = ocrTesseract.Read(ocrInput) ' Draws the rectangle from above in a blue bounding box on the image for visualization. ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png")EndUsing
Imports IronOcr
Imports IronSoftware.Drawing
Dim ocrTesseract = New IronTesseract()
Using ocrInput As New OcrInput()
' Define the specific rectangular area to scan within the image.
' The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.
Dim ContentArea As New Rectangle(x:=4, y:=59, width:=365, height:=26)
ocrInput.LoadImage("region-input.png", ContentArea)
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Draws the rectangle from above in a blue bounding box on the image for visualization.
ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png")
End Using
Is it possible to visualize the OCR region on the input image?
Yes, you can visualize the OCR region by using the `StampCropRectangleAndSaveAs` method to draw the specified rectangle on the input image, aiding in coordinate verification.
For what applications is regional OCR particularly useful?
Regional OCR is useful for form processing, invoice scanning, license plate recognition, identity document analysis, and extracting text from UI elements in screenshots.
What are some best practices for using regional OCR in document processing?
Best practices include adding padding around text, testing with sample images, handling slight document variations, optimizing performance with multithreading, and monitoring result confidence scores.
How can I improve the accuracy of IronOCR's regional scanning?
Improve accuracy by using high-resolution images, ensuring proper text orientation, applying contrast and clarity filters, and verifying the targeted region visually.
Can IronOCR be used with different image formats?
Yes, IronOCR supports various image formats including JPG, PNG, GIF, TIFF, and BMP, making it versatile for different scanning and processing needs.