IRONSOFTWAREHOME

如何在C#中使用IronOCR讀取車牌

Curtis Chau
Curtis Chau
Updated: 2026年6月4日

IronOCR的ReadLicensePlate方法使用先進的OCR技術自動從車輛圖像中提取車牌號碼。 這個單一的方法調用可以高精度地處理車牌,返回車牌文字和信心水準,適用於自動車輛管理系統。

在管理大量車輛圖片時,手動讀取車牌既費時又易出人為錯誤。 使用像IronOCR這樣的工具自動化此過程,提供了更高效、精確的解決方案。 IronOCR的ReadLicensePlate方法可程式化地從圖像中提取車牌號碼,節省大量時間並提高資料準確性。

在本指南中,我們將展示如何使用IronOCR進行車牌識別,並介紹例子和可自定義的配置,使過程更為順暢。 通過利用這些方法,開發者可以自動化車牌讀取,讓停車管理、收費管理或安全監控等任務更加高效。

要使用此功能,您必須同時安裝IronOcr.Extension.AdvancedScan套件。

快速開始:立即提取車牌號

使用IronOCR的ReadLicensePlate只需一個方法調用,就可以程式化地從任何圖像中提取車牌文字。 它已經可以使用——只需載入圖像、調用方法,即刻獲取車牌號碼和信心值。

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2複製並運行這段程式碼片段。

    OcrLicensePlateResult result = new IronTesseract().ReadLicensePlate(new OcrInput("plate.jpg"));
    C#
  3. 3部署以在您的實時環境中測試

    今天就開始在您的專案中使用IronOCR,透過免費試用
    arrow pointer

如何在C#中讀取車牌?

要在IronOCR中讀取車牌,我們應用以下步驟:

  • 我們利用ReadLicensePlate方法,它需要一個OcrInput作為輸入參數。 這個方法對比該程式庫的標準Read更優化於車牌。
  • 可選地,我們可以配置IronOCR將車牌中可能存在的字元加入白名單,以加速車牌號的處理。
請注意:
  • 該方法目前僅適用於英文、中文、日文、韓文和拉丁字母腳本。
  • 在.NET Framework上使用高級掃瞄需要專案在x64架構上運行。 )}]

輸入的車牌長什麼樣子?

加州車牌顯示'8TRS777'——車牌讀取示範例子

如何配置OCR以讀取車牌?

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);

應該期望什麼結果?

除錯控制台顯示車牌OCR結果:加利福尼亞州,車牌8TRS777,自信度95.87%

程式碼示範如何將一個圖像導入為ReadLicensePlate方法從車牌中提取文字。 輸出顯示與輸入圖像中車牌相匹配的提取文字,以及顯示OCR準確性的信心水準。

文字:從OCR輸入中提取的文字。

信心:一個double屬性,指示每個字元平均的統計準確性信心水準,1為最高,0為最低。

要對OCR過程進行更精確的控制,您可以探索高級配置選項來微調字元識別設定。


如何從汽車圖像中提取車牌?

該方法對於包含車牌的汽車圖像也表現良好。 程式碼與上述相同,只改變了輸入圖像。 您還可以提取圖像中車牌所在區域的像素座標。

什麼型別的汽車圖像效果最好?

深灰色斯柯達汽車顯示馬哈拉施特拉州車牌MH 20 EE 7602停在磚塊地上

為獲得最佳效果,確保您的汽車圖像具有:

  • 清晰可見的車牌
  • 良好的照明狀況(避免眩光或陰影)
  • 最小的角度變形
  • 足夠的解析度(可考慮為低清晰度的圖像調整DPI設定

如何獲得車牌位置的座標?

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);

結果包括哪些資訊?

Visual Studio除錯輸出顯示檢測到的車牌MH20EE7602,帶有邊框座標和尺寸

範例展示了如何將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;

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();

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 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);

深入的性能監控,探索IronOCR中的進度追踪能力

這與其他文件讀取相比如何?

IronOCR的專業文件讀取能力不僅限於車牌。 同樣的機器視覺技術也可用於:

有哪些常見的使用案例?

使用IronOCR進行車牌識別可實現多種應用:

  • 停車管理:自動化進出記錄和支付處理
  • 收費管理:加快在收費站的車輛識別
  • 安全監控:追踪限制區域內的車輛動向
  • 車隊管理:監控公司車輛和物流
  • 執法:快速識別感興趣的車輛

每個使用案例都受益於IronOCR的高準確性和即時處理圖像的能力,適用於批量處理和即時應用。

常見問題

如何在C#中從圖像中讀取車牌?

您可以使用IronOCR的ReadLicensePlate方法在C#中讀取車牌。只需建立一個IronTesseract實例並調用ReadLicensePlate,其中包括您的車牌圖像的OcrInput。該方法返回包含提取出的車牌文字和置信度分數的OcrLicensePlateResult。

讀取車牌識別需要安裝什麼套件?

要使用IronOCR的車牌識別功能,您需要從NuGet安裝主IronOCR套件和IronOcr.Extension.AdvancedScan套件。AdvancedScan擴展提供了專門的ReadLicensePlate方法。

我能否僅用一行程式碼提取車牌?

是的,IronOCR允許您用一行程式碼提取車牌文字:OcrLicensePlateResult result = new IronTesseract().ReadLicensePlate(new OcrInput("plate.jpg")); 這會立即返回車牌號碼和置信度分數。

車牌識別支持哪些語言?

IronOCR的ReadLicensePlate方法目前支持包含英語、漢語、日語、韓語和拉丁字母的車牌。該方法專門為這些字元集進行了優化。

如何提高車牌讀取的準確性?

您可以通過白名單化車牌中出現的特定字元、確保圖像僅包含車牌無標頭或標尾以及使用高質量的圖像來提高IronOCR的準確性。ReadLicensePlate方法已專為車牌識別優化。

.NET Framework上的車牌識別系統需求是什麼?

在使用IronOCR的高級掃描功能(包括ReadLicensePlate)於.NET Framework時,您的專案必須在x64架構上運行。此要求確保車牌識別功能的最佳性能。

車牌識別返回什麼資訊?

IronOCR的ReadLicensePlate方法返回一個OcrLicensePlateResult物件,內含提取出的車牌文字和置信度分數。這使您可以檢索車牌號碼並評估OCR結果的可靠性。

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.

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備開始了嗎?

Nuget Downloads 6,236,385版本:2026.9剛剛發布

立即獲取免費

立即獲取 30天試用金鑰

bullet_checked無需信用卡或註冊帳號
bullet_test在生產
環境中進行測試,且不顯示浮水印
bullet_calendar30 天全
功能產品
bullet_support試用期間提供 24/5 技術
支援
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立
C# PDF的NuGet程式庫
使用NuGet安裝

版本: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. 在解決方案資源管理器中,右鍵點擊參考,管理NuGet包
  2. 選擇瀏覽並搜尋"IronOCR"
  3. 選擇包並安裝
C# PDF DLL
下載 DLL

版本: 2026.9

這裡下載Windows安裝程式。

  1. 下載並解壓IronOCR至您的方案目錄下的~/Libs等位置
  2. 在Visual Studio解決方案資源管理器中,右鍵點擊參考。選擇瀏覽,"IronOCR.dll"

授權從$999

有問題嗎?聯絡我們的開發團隊。

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
被全球數百萬工程師信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立