如何使用 C# OCR 讀取車牌

How to Read License Plates using IronOCR

This article was translated from English: Does it need improvement?
Translated
View the article in English

當管理大量的車輛圖像時,手動讀取車牌既耗時又容易出錯。 使用像 IronOCR 這樣的工具自動化此過程可以提供更高效且準確的解決方案。 IronOCR 的 ReadLicensePlate 方法可以程式化地從圖像中提取車牌號碼,大大節省時間並提高數據準確性。

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

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

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

通過 IronOCR 的 ReadLicensePlate 的單一方法調用,您可以程式化地從任何圖像中提取車牌文字。 它已準備就緒——只需加載圖像,調用方法,即可立即獲得車牌號和信心水平。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    OcrLicensePlateResult result = new IronTesseract().ReadLicensePlate(new OcrInput("plate.jpg"));
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小工作流程(5 步)

  1. 下載用於讀取車牌的 C# 程式庫
  2. 導入要處理的車牌圖像
  3. 確保文件僅包含車牌圖像,沒有頁眉或頁尾
  4. 使用 ReadLicensePlate 方法從圖像中提取數據
  5. 訪問 OcrLicensePlateResult 屬性以查看和操作提取的車牌數據

讀取車牌示例

要在 IronOCR 中讀取車牌,我們必須執行以下步驟:

  • 我們使用 ReadLicensePlate 方法,該方法將 OcrInput 作為輸入的參數。 這種方法比圖書館的標準 Read 方法更適合用於車牌。
  • 我們可以選擇性地配置 IronOCR 以僅白名單能出現在車牌中的特定字符,以加速車牌號的處理。

請注意

  • 該方法目前僅適用於英語、中文、日語、韓語和拉丁字母的文本。
  • 在 .NET Framework 上使用高級掃描需要項目在 x64 架構上運行。

車牌

車牌

代碼

: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)
$vbLabelText   $csharpLabel

輸出

車牌結果

代碼演示了如何將圖像導入為 OcrInput 並使用 ReadLicensePlate 方法從車牌中提取文本。 輸出顯示了從輸入圖像中顯示的車牌提取的文本,以及表明 OCR 準確性的置信度水平。

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

信心: 一個“double”類型的屬性,表示每個字符的統計準確性置信度,其中 1 為最高,0 為最低。


來自汽車圖像的車牌

該方法也適用於包含車牌的汽車圖像。 代碼與上述相同,只是更改了輸入圖像。 您還可以提取圖像中車牌所在區域的像素坐標。

示例輸入

汽車車牌

: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)
$vbLabelText   $csharpLabel

輸出

汽車車牌結果

該示例顯示了 ReadLicensePlate 方法如何應用於汽車圖像。 該方法還將返回車牌位於圖像中的矩形坐標。

此方法經過優化僅查找單個車牌,并且能够在库存图像中搜索它们。

常見問題解答

如何使用 C# 實現車牌自動辨識?

您可以使用 IronOCR 的ReadLicensePlate方法在 C# 中實現車牌識別自動化。此方法可讓您從影像中提取車牌號碼,與手動方法相比,效率和準確性均有所提高。

使用 IronOCR 讀取車牌需要哪些步驟?

要使用 IronOCR 讀取車牌,請下載 C# 庫,將車牌圖像作為OcrInput匯入,然後使用ReadLicensePlate方法提取資料。之後,您可以存取OcrLicensePlateResult屬性進行進一步處理。

IronOCR 能否處理有清晰可見車牌的汽車影像?

是的,IronOCR可以從汽車影像中讀取車牌號碼。它還可以提供車牌在圖像中的像素座標。

IronOCR支援哪些語言的車牌辨識?

IronOCR 的ReadLicensePlate方法支援英文、中文、日文、韓文和拉丁字母腳本進行車牌辨識。

配置字元白名單如何增強車牌辨識能力?

透過配置 IronOCR 將車牌中常見的特定字元列入白名單,可以提高辨識效能並加快車牌號碼的處理速度。

進階車牌掃描功能需要哪些額外的軟體套件?

若要使用進階掃描功能,您需要安裝IronOcr.Extensions.AdvancedScan軟體套件。

車牌辨識中置信度的意義是什麼?

車牌辨識的置信度表示 OCR 過程的統計準確性,範圍從 0 到 1,其中 1 代表最高的置信度。

IronOCR 是如何針對 .NET Framework 進行車牌讀取最佳化的?

IronOCR 針對在 x64 架構上運行時的 .NET Framework 進行了最佳化,可讀取車牌,從而確保高效的處理和識別效能。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 5,044,537 | 版本: 2025.11 剛剛發布