如何使用 IronOCR 在 C# 中讀取車牌
IronOCR 的 ReadLicensePlate 方法運用先進的 OCR 技術,能自動從車輛影像中擷取車牌號碼。 此單一方法呼叫能以高準確度處理車牌,並同時回傳車牌文字與信心分數,適用於自動化車輛管理系統。
在處理大量車輛影像時,人工辨識車牌不僅耗時,且容易發生人為錯誤。 透過 IronOCR 等工具自動化此流程,能提供更高效且精準的解決方案。 IronOCR 的 ReadLicensePlate 方法可透過程式化方式從圖像中擷取車牌號碼,不僅能節省大量時間,更能提升資料準確性。
在本指南中,我們將示範如何使用 IronOCR 進行車牌辨識,並透過範例與可自訂的設定,引導您完成流暢無縫的流程。 透過運用這些方法,開發人員可實現車牌辨識的自動化,從而提升停車管理、收費或安全監控等任務的效率。
若要使用此功能,您還必須安裝 IronOcr.Extension.AdvancedScan 套件。
快速入門:立即擷取車牌號碼
透過 IronOCR 的 ReadLicensePlate 單一方法呼叫,您即可透過程式化方式從任何圖片中擷取車牌文字。 它已準備就緒——只需載入圖片、呼叫方法,即可立即取得車牌號碼與辨識精準度。
簡化工作流程(5 個步驟)
- 下載用於讀取車牌的 C# 函式庫
- 匯入車牌圖片以進行處理
- 請確保文件僅包含車牌影像,不含頁首或頁尾
- 使用
ReadLicensePlate方法從圖片中提取資料 - 透過存取 OcrLicensePlateResult 屬性,即可檢視並處理已擷取的車牌資料
如何用 C# 讀取車牌號碼?
要在 IronOCR 中讀取車牌,我們會執行以下步驟:
- 我們採用
ReadLicensePlate方法,該方法將OcrInput作為輸入參數。 相較於該函式庫標準的Read對應版本,此方法針對車牌編碼的處理更為優化。 - 若需加速車牌號碼的處理,我們可選擇性地將車牌中可能出現的特定字元加入 IronOCR 的白名單中。
- 此方法目前僅適用於英語、中文、日語、韓語及拉丁字母系統。
- 若要在 .NET Framework 上使用進階掃描功能,專案必須在 x64 架構上執行。 )}]
輸入的車牌外觀為何?

如何設定車牌號碼的 OCR 功能?
:path=/static-assets/ocr/content-code-examples/how-to/read-license-plate-read-license-plate.cs
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);
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)
我應該期待什麼樣的成果?

此程式碼範例展示如何將圖片匯入為 OcrInput,並透過 ReadLicensePlate 方法從車牌中擷取文字。 輸出結果會顯示與輸入圖片中車牌相符的擷取文字,並附有表示 OCR 準確度的信心水準。
文字:從 OCR 輸入中擷取的文字。
信心值:double 屬性,用以表示每個字元平均值的統計準確度信心值,1 代表最高,0 代表最低。
若需更精確地控制 OCR 流程,您可以探索進階設定選項,以微調字元辨識設定。
如何從汽車圖片中擷取車牌號碼?
此方法對於包含車牌的汽車圖片同樣效果良好。 程式碼與上文相同,僅變更了輸入圖片。 您也可以擷取圖片中車牌所在區域的像素座標。
哪種類型的汽車圖片效果最佳?

為獲得最佳效果,請確保您的汽車圖片具備:
- 車牌清晰可見
- 良好的照明條件(避免眩光或陰影)
- 盡量減少視角失真
- 適當的解析度(針對低解析度圖片,請考慮調整 DPI 設定)
如何取得車牌位置的座標?
:path=/static-assets/ocr/content-code-examples/how-to/read-license-plate-read-from-car.cs
using IronOcr;
using IronSoftware.Drawing;
using System;
var ocr = new IronTesseract();
using var inputLicensePlate = new OcrInput();
inputLicensePlate.LoadImage("car_license.jpg");
// Read license plate
OcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);
// Retrieve license plate coordinates
RectangleF rectangle = result.Licenseplate;
// Write license plate value and coordinates in a string
string output = $"License Plate Number:\n{result.Text}\n\n"
+ $"License Plate Area_\n"
+ $"Starting X: {rectangle.X}\n"
+ $"Starting Y: {rectangle.Y}\n"
+ $"Width: {rectangle.Width}\n"
+ $"Height: {rectangle.Height}";
Console.WriteLine(output);
Imports Microsoft.VisualBasic
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
Private ocr = New IronTesseract()
Private inputLicensePlate = New OcrInput()
inputLicensePlate.LoadImage("car_license.jpg")
' Read license plate
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate)
' Retrieve license plate coordinates
Dim rectangle As RectangleF = result.Licenseplate
' Write license plate value and coordinates in a string
Dim output As String = $"License Plate Number:" & vbLf & "{result.Text}" & vbLf & vbLf & $"License Plate Area_" & vbLf & $"Starting X: {rectangle.X}" & vbLf & $"Starting Y: {rectangle.Y}" & vbLf & $"Width: {rectangle.Width}" & vbLf & $"Height: {rectangle.Height}"
Console.WriteLine(output)
翻譯結果包含哪些資訊?

此範例展示了如何將 ReadLicensePlate 方法應用於汽車圖片。 此方法還會返回車牌在圖片中所處位置的矩形座標。
此方法專為識別單一車牌而優化,並能從庫存圖片中搜尋車牌。
如何處理多個車牌號碼?
當處理多張車輛圖片時,您可以透過批次操作來高效處理它們:
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})");
}
}
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})");
}
}
Imports IronOcr
Imports System.IO
Imports System.Threading.Tasks
Public Async Function ProcessMultipleLicensePlates(imagePaths As String()) As Task
Dim ocr As New IronTesseract()
' Configure for optimal performance
ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock
Dim tasks = imagePaths.Select(Async Function(path)
Using input As New OcrInput()
input.LoadImage(path)
Dim result = Await Task.Run(Function() ocr.ReadLicensePlate(input))
Return New With {
.FilePath = path,
.PlateNumber = result.Text,
.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 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);
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);
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 contrast
input.Brightness(1.2); // Adjust brightness
input.Binarize(); // Convert to black and white for clarity
var 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.Brightness(1.2); // Adjust brightness
input.Binarize(); // Convert to black and white for clarity
var result = ocr.ReadLicensePlate(input);
Imports IronOcr
Dim ocr As New IronTesseract()
Using input As New OcrInput()
input.LoadImage("dark_plate.jpg")
input.Contrast(1.5) ' Increase contrast
input.Brightness(1.2) ' Adjust brightness
input.Binarize() ' Convert to black and white for clarity
Dim result = ocr.ReadLicensePlate(input)
End Using
如何監控 OCR 效能?
在處理大量車牌資料時,追蹤進度有助於管理系統資源:
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);
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);
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
若需進行詳細的效能監控,請探索 IronOCR 中的進度追蹤功能。
這與其他文件閱讀功能有何不同?
IronOCR 的專業文件讀取能力不僅限於車牌。 驅動車牌辨識的相同電腦視覺技術,亦可應用於:
常見的使用情境有哪些?
透過 IronOCR 進行車牌辨識可應用於多種場景:
- 停車管理:自動化進出記錄與付款處理
- 收費系統:加速收費站車輛識別流程
- 安全監控:追蹤限制區域內的車輛動向
- 車隊管理:監控公司車輛與物流
- 執法單位:快速識別目標車輛
每種應用情境皆能受益於 IronOCR 的高準確度與即時影像處理能力,使其同時適用於批次處理與即時應用。
常見問題
如何在 C# 中從圖片中讀取車牌號碼?
您可以使用 IronOCR 的 ReadLicensePlate 方法,透過 C# 讀取車牌。只需建立一個 IronTesseract 實例,並傳入包含車牌影像的 OcrInput 來呼叫 ReadLicensePlate 方法。該方法會傳回一個 OcrLicensePlateResult 物件,其中包含已擷取的車牌文字及信心分數。
進行車牌辨識需要安裝哪個套件?
若要使用 IronOCR 中的車牌辨識功能,您需要從 NuGet 安裝 IronOCR 主套件以及 IronOcr.Extensions.AdvancedScan 套件。AdvancedScan 擴充套件提供了專用的 ReadLicensePlate 方法。
我能否僅用一行程式碼就擷取車牌號碼?
是的,IronOCR 允許您透過單行程式碼提取車牌文字:OcrLicensePlateResult result = new IronTesseract().ReadLicensePlate(new OcrInput("plate.jpg")); 此程式碼會立即返回車牌號碼及信心分數。
車牌辨識支援哪些語言?
IronOCR 的 ReadLicensePlate 方法目前支援英文、中文、日文、韓文及拉丁字母字元的車牌。此方法已針對這些字元集進行了特別優化。
如何提高車牌辨識的準確度?
您可透過將車牌上的特定字元加入白名單、確保影像僅包含車牌(不含頁首或頁尾),以及使用高畫質影像,來提升 IronOCR 的辨識準確度。ReadLicensePlate 方法已針對車牌辨識進行了專門優化。
在 .NET Framework 上進行車牌辨識的系統需求為何?
當您在 .NET Framework 上使用 IronOCR 的進階掃描功能(包括 ReadLicensePlate)時,您的專案必須在 x64 架構上運行。此要求可確保車牌辨識功能達到最佳效能。
車牌辨識功能會回傳哪些資訊?
IronOCR 的 ReadLicensePlate 方法會傳回一個 OcrLicensePlateResult 物件,其中包含擷取的車牌文字及信心分數。這讓您既能取得車牌號碼,也能評估 OCR 結果的可靠性。
使用 IronOCR 進行文件管理有哪些好處?
使用 IronOCR 進行文件管理,可將掃描文件轉換為可搜尋且可編輯的文字,從而簡化工作流程,減少人工資料輸入的需求,並提升文件的可存取性。
IronOCR 如何提升資料準確性?
IronOCR 透過其先進的辨識演算法與影像校正功能來提升資料準確性,確保文字擷取過程既可靠又精確。
IronOCR 是否有提供免費試用版?
是的,Iron Software 提供 IronOCR 的免費試用版,讓使用者能在決定購買前測試其功能與效能。

