using IronOcr;using System;var ocr = new IronTesseract();ocr.Configuration.WhiteListCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";using var inputLicensePlate = new OcrInput();inputLicensePlate.LoadImage("plate.jpeg");// Read license plateOcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);// Retrieve license plate number and confidence valuestring output = $"{result.Text}\nResult Confidence: {result.Confidence}";Console.WriteLine(output);
using IronOcr;
using System;
var ocr = new IronTesseract();
ocr.Configuration.WhiteListCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
using var inputLicensePlate = new OcrInput();
inputLicensePlate.LoadImage("plate.jpeg");
// Read license plate
OcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);
// Retrieve license plate number and confidence value
string output = $"{result.Text}\nResult Confidence: {result.Confidence}";
Console.WriteLine(output);
ImportsMicrosoft.VisualBasicImportsIronOcrImportsSystemPrivate ocr = New IronTesseract()ocr.Configuration.WhiteListCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"Dim inputLicensePlate = New OcrInput()inputLicensePlate.LoadImage("plate.jpeg")' Read license plateDim result AsOcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate)' Retrieve license plate number and confidence valueDim output AsString = $"{result.Text}" & vbLf & "Result Confidence: {result.Confidence}"Console.WriteLine(output)
Imports Microsoft.VisualBasic
Imports IronOcr
Imports System
Private ocr = New IronTesseract()
ocr.Configuration.WhiteListCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
Dim inputLicensePlate = New OcrInput()
inputLicensePlate.LoadImage("plate.jpeg")
' Read license plate
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate)
' Retrieve license plate number and confidence value
Dim output As String = $"{result.Text}" & vbLf & "Result Confidence: {result.Confidence}"
Console.WriteLine(output)
using IronOcr;using System.IO;using System.Threading.Tasks;public async TaskProcessMultipleLicensePlates(string[] imagePaths){ var ocr = new IronTesseract(); // Configure for optimal performance ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock; var tasks = imagePaths.Select(async path => { using var input = new OcrInput(); input.LoadImage(path); var result = awaitTask.Run(() => ocr.ReadLicensePlate(input)); return new { FilePath = path, PlateNumber = result.Text, Confidence = result.Confidence }; }); var results = awaitTask.WhenAll(tasks); // Process results foreach (var result in results) {Console.WriteLine($"File: {result.FilePath}");Console.WriteLine($"Plate: {result.PlateNumber} (Confidence: {result.Confidence:P})"); }}
using IronOcr;
using System.IO;
using System.Threading.Tasks;
public async Task ProcessMultipleLicensePlates(string[] imagePaths)
{
var ocr = new IronTesseract();
// Configure for optimal performance
ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock;
var tasks = imagePaths.Select(async path =>
{
using var input = new OcrInput();
input.LoadImage(path);
var result = await Task.Run(() => ocr.ReadLicensePlate(input));
return new {
FilePath = path,
PlateNumber = result.Text,
Confidence = result.Confidence
};
});
var results = await Task.WhenAll(tasks);
// Process results
foreach (var result in results)
{
Console.WriteLine($"File: {result.FilePath}");
Console.WriteLine($"Plate: {result.PlateNumber} (Confidence: {result.Confidence:P})");
}
}
ImportsIronOcrImportsSystem.IOImportsSystem.Threading.TasksPublicAsync Function ProcessMultipleLicensePlates(imagePaths AsString()) AsTask Dim ocr = New IronTesseract() ' Configure for optimal performance ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock Dim tasks = imagePaths.Select(Async Function(path)Using input = New OcrInput() input.LoadImage(path) Dim result = AwaitTask.Run(Function() ocr.ReadLicensePlate(input)) Return New With {Key .FilePath = path,Key .PlateNumber = result.Text,Key .Confidence = result.Confidence }EndUsing End Function) Dim results = AwaitTask.WhenAll(tasks) ' Process results For Each result In resultsConsole.WriteLine($"File: {result.FilePath}")Console.WriteLine($"Plate: {result.PlateNumber} (Confidence: {result.Confidence:P})") NextEnd Function
Imports IronOcr
Imports System.IO
Imports System.Threading.Tasks
Public Async Function ProcessMultipleLicensePlates(imagePaths As String()) As Task
Dim ocr = New IronTesseract()
' Configure for optimal performance
ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock
Dim tasks = imagePaths.Select(Async Function(path)
Using input = New OcrInput()
input.LoadImage(path)
Dim result = Await Task.Run(Function() ocr.ReadLicensePlate(input))
Return New With {
Key .FilePath = path,
Key .PlateNumber = result.Text,
Key .Confidence = result.Confidence
}
End Using
End Function)
Dim results = Await Task.WhenAll(tasks)
' Process results
For Each result In results
Console.WriteLine($"File: {result.FilePath}")
Console.WriteLine($"Plate: {result.PlateNumber} (Confidence: {result.Confidence:P})")
Next
End Function
using IronOcr;var ocr = new IronTesseract();using var input = new OcrInput();// Load and preprocess the imageinput.LoadImage("blurry_plate.jpg");input.Deskew(); // Correct image rotationinput.DeNoise(); // Remove background noiseinput.EnhanceResolution(225); // Upscale for better clarityinput.Sharpen(); // Enhance edge definitionvar result = ocr.ReadLicensePlate(input);
using IronOcr;
var ocr = new IronTesseract();
using var input = new OcrInput();
// Load and preprocess the image
input.LoadImage("blurry_plate.jpg");
input.Deskew(); // Correct image rotation
input.DeNoise(); // Remove background noise
input.EnhanceResolution(225); // Upscale for better clarity
input.Sharpen(); // Enhance edge definition
var result = ocr.ReadLicensePlate(input);
ImportsIronOcrDim ocr As New IronTesseract()Using input As New OcrInput() ' Load and preprocess the image input.LoadImage("blurry_plate.jpg") input.Deskew() ' Correct image rotation input.DeNoise() ' Remove background noise input.EnhanceResolution(225) ' Upscale for better clarity input.Sharpen() ' Enhance edge definition Dim result = ocr.ReadLicensePlate(input)EndUsing
Imports IronOcr
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Load and preprocess the image
input.LoadImage("blurry_plate.jpg")
input.Deskew() ' Correct image rotation
input.DeNoise() ' Remove background noise
input.EnhanceResolution(225) ' Upscale for better clarity
input.Sharpen() ' Enhance edge definition
Dim result = ocr.ReadLicensePlate(input)
End Using
using IronOcr;var ocr = new IronTesseract();using var input = new OcrInput();input.LoadImage("dark_plate.jpg");input.Contrast(1.5); // Increase contrastinput.Binarize(); // Convert to black and white for clarityvar result = ocr.ReadLicensePlate(input);
using IronOcr;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("dark_plate.jpg");
input.Contrast(1.5); // Increase contrast
input.Binarize(); // Convert to black and white for clarity
var result = ocr.ReadLicensePlate(input);
C#
如何监控 OCR 性能?
在处理大批量车牌时,跟踪进度有助于管理系统资源:
using IronOcr;var ocr = new IronTesseract();// Subscribe to progress eventsocr.OcrProgress += (sender, e) => {Console.WriteLine($"Processing: {e.ProgressPercent}% complete");};using var input = new OcrInput();input.LoadImage("large_parking_lot.jpg");var result = ocr.ReadLicensePlate(input);
using IronOcr;
var ocr = new IronTesseract();
// Subscribe to progress events
ocr.OcrProgress += (sender, e) =>
{
Console.WriteLine($"Processing: {e.ProgressPercent}% complete");
};
using var input = new OcrInput();
input.LoadImage("large_parking_lot.jpg");
var result = ocr.ReadLicensePlate(input);
ImportsIronOcrDim ocr As New IronTesseract()' Subscribe to progress eventsAddHandler ocr.OcrProgress, Sub(sender, e)Console.WriteLine($"Processing: {e.ProgressPercent}% complete") End SubUsing input As New OcrInput() input.LoadImage("large_parking_lot.jpg") Dim result = ocr.ReadLicensePlate(input)EndUsing
Imports IronOcr
Dim ocr As New IronTesseract()
' Subscribe to progress events
AddHandler ocr.OcrProgress, Sub(sender, e)
Console.WriteLine($"Processing: {e.ProgressPercent}% complete")
End Sub
Using input As New OcrInput()
input.LoadImage("large_parking_lot.jpg")
Dim result = ocr.ReadLicensePlate(input)
End Using
What are common use cases for license plate recognition with IronOCR?
Common use cases include parking management, toll collection, security surveillance, fleet management, and law enforcement - all benefiting from IronOCR's high accuracy and real-time processing capabilities.
What type of images provide the best results for IronOCR?
Images with clear visibility of the license plate, good lighting conditions, minimal angle distortion, and adequate resolution provide the best results when using IronOCR for license plate recognition.
How can I monitor IronOCR's performance during license plate recognition?
You can monitor IronOCR's performance by subscribing to its `OcrProgress` event, which provides real-time progress information during the processing of large batches of license plate images.