跳過到頁腳內容
使用 IRONOCR

如何在 C# 中進行車輛註冊 OCR

車輛登記號碼牌是任何車輛的重要組成部分,作為法律和行政用途的唯一識別碼。 這些牌照通常包含字母和數字字符,代表信息,如車輛的註冊號或車輛識別號碼、管轄區域,有時還包括附加細節。 在汽車行業中,各種檢查點不斷有車輛通過,這需要高效且準確的方法來提取和處理數據。 高效提取此信息對於各種車輛登記應用程序至關重要,包括執法、停車管理和車輛跟踪。

在本文中,我們將探討如何使用光學字符識別(OCR)技術,通過不同的號碼牌格式,從車輛註冊中高效提取數據,重點是在C#中使用IronOCR庫實現此功能。

如何在C#中執行車輛註冊OCR

  1. 安裝 C# 中的 IronOCR 庫,用於車輛註冊 OCR(光學字符識別)。
  2. 使用 OcrInput LoadImage 方法導入圖像。
  3. 應用 FindTextRegion 來改善自動號碼牌識別。
  4. 使用 IronTesseract Read 方法提取數據。
  5. 打印出車輛註冊文件數據以進行號牌識別。

自動號牌識別的重要性

自動號牌識別(ANPR)系統徹底改變了我們處理車輛註冊文件或車輛註冊證書的方式。 繁瑣的手動數據輸入已成過去,特別是在處理像德國車輛註冊文件這樣複雜的格式時。 通過 ANPR 技術,號牌識別變得高度高效,能夠準確提取具有不同格式的號牌數據。

此技術在車輛註冊應用中尤為寶貴,因為速度和精確度至關重要。 自動捕捉包括車輛識別號碼在內的號牌信息,ANPR 系統簡化了從車輛註冊證書中提取數據的過程,相比於手動數據錄入降低了錯誤並提高了整體效率。

光學字符識別(OCR)技術在自動從車輛註冊號牌中提取信息方面發揮了關鍵作用。 通過使用 OCR 解決方案,企業和組織可以簡化流程,自動化工作流,提高精確度,並提升整體效率。

IronOCR - C# 的 OCR 軟件庫

IronOCR 是一個強大的 .NET 庫,為 C# 和其他 .NET 語言提供全面的 OCR 功能。 它為開發人員提供了一種直觀且高效的方式來執行 OCR 任務,包括從圖像、PDF 和掃描文檔中提取文本。 憑藉其強大的功能和簡易集成,IronOCR 簡化了在各種應用中實現 OCR 功能的過程。

IronOCR的主要特點

  • 從圖像和掃描文檔中準確提取文本。
  • 支持包括 JPEG、PNG、BMP 和 TIFF 在內的多種圖像格式。
  • 高級圖像處理算法以提高 OCR 精度。
  • 多語言支持,允許識別不同語言的文本。
  • 靈活的配置選項,根據具體需求優化 OCR 性能。
  • 與 .NET 應用程序無縫集成,使得將 OCR 功能整合到現有項目中變得容易。

必要條件

在繼續之前,請確保您有以下條件:

  • 系統上安裝了 Visual Studio 2022。
  • 對 C# 編程有基本了解。
  • 可訪問 NuGet 包管理器以安裝依賴項。

創建C# Visual Studio項目的步驟

  1. 打開 Visual Studio 並創建一個新的 C# 項目。

如何在 C# 中執行車輛註冊 OCR:圖 1 - Visual Studio

  1. 根據需要選擇適當的項目模板(例如,控制台應用程序、Windows 窗體應用程序)。

如何在 C# 中執行車輛註冊 OCR:圖 2 - 新項目

  1. 指定項目名稱和位置,然後點擊“下一步”。

如何在 C# 中執行車輛註冊 OCR:圖 3 - 項目配置

  1. 從附加信息中選擇最新的 .NET 框架。 IronOCR 支持最新的 .NET 8.0。點擊“創建”來創建項目。

使用 NuGet 包管理器安裝 IronOCR 庫

要在您的 Visual Studio 項目中安裝 IronOCR:

  1. 打開NuGet包管理控制台。
  2. 運行以下命令以安裝 IronOCR:

    Install-Package IronOcr
  3. 或者,您可以右鍵點擊解決方案資源管理器 -> 管理 NuGet 包 來進行安裝。
  4. 在瀏覽選項卡中搜索 IronOCR,然後點擊安裝。

如何在 C# 中執行車輛註冊 OCR:圖 4 - 安裝 IronOCR

多種方法的車輛註冊版 OCR

1. 從號牌圖像中提取車輛信息

OCR 技術的一個主要任務是從包含車輛註冊號牌的圖像中提取信息。 通過利用 IronOCR,我們可以高精確度地輕鬆完成此任務。 無論是獨立的號牌圖像還是大型文檔的一部分,IronOCR 使我們能高效地提取相關數據。

要使用 IronOCR 從獨立的號牌圖像中提取信息,可以使用以下代碼:

using IronOcr; // Import IronOcr namespace

var ocrTesseract = new IronTesseract(); // Initialize IronTesseract object
using var ocrInput = new OcrInput(); // Create an OcrInput object to hold the image
ocrInput.DeNoise(); // Fixes digital noise and poor scanning
ocrInput.ToGrayScale(); // Converts the image to grayscale
ocrInput.LoadImage(@"images\image.png"); // Load the image for OCR processing
var ocrResult = ocrTesseract.Read(ocrInput); // Perform OCR on the image
Console.WriteLine(ocrResult.Text); // Output the extracted text
using IronOcr; // Import IronOcr namespace

var ocrTesseract = new IronTesseract(); // Initialize IronTesseract object
using var ocrInput = new OcrInput(); // Create an OcrInput object to hold the image
ocrInput.DeNoise(); // Fixes digital noise and poor scanning
ocrInput.ToGrayScale(); // Converts the image to grayscale
ocrInput.LoadImage(@"images\image.png"); // Load the image for OCR processing
var ocrResult = ocrTesseract.Read(ocrInput); // Perform OCR on the image
Console.WriteLine(ocrResult.Text); // Output the extracted text
Imports IronOcr ' Import IronOcr namespace

Private ocrTesseract = New IronTesseract() ' Initialize IronTesseract object
Private ocrInput = New OcrInput() ' Create an OcrInput object to hold the image
ocrInput.DeNoise() ' Fixes digital noise and poor scanning
ocrInput.ToGrayScale() ' Converts the image to grayscale
ocrInput.LoadImage("images\image.png") ' Load the image for OCR processing
Dim ocrResult = ocrTesseract.Read(ocrInput) ' Perform OCR on the image
Console.WriteLine(ocrResult.Text) ' Output the extracted text
$vbLabelText   $csharpLabel

上述代碼初始化了 IronTesseract 對象,為 OCR 處理加載了一個圖像文件,使用 Read 方法在圖像上執行 OCR,並將提取的文本打印到控制台。 這顯示了 IronOCR 的簡單性,無需煩惱即可從圖像中提取文本。

如需更強大的 IronOCR 用法,請訪問此代碼示例頁面。

輸入圖像

如何在 C# 中執行車輛註冊 OCR:圖 5 - 車輛註冊輸入

輸出

如何在 C# 中執行車輛註冊 OCR:圖 6 - 車輛註冊 OCR 軟件輸出

2. 使用計算機視覺提高精確度

為了進一步提高精確度,IronOCR 提供計算機視覺能力的集成。 通過利用計算機視覺機器學習算法,IronOCR 可以自動檢測圖像中對應於車輛註冊版的文字區域。 這種自動檢測過程確保僅分析相關區域以進行文本提取,導致更準確的結果。

要利用 IronOCR 的計算機視覺功能進行自動文本區域檢測以提高精確度,可以使用以下代碼:

using IronOcr; // Import IronOcr namespace

var ocr = new IronTesseract(); // Initialize IronTesseract object
using var input = new OcrInput(); // Create an OcrInput object to hold the image
input.LoadImage("/path/file.png"); // Load the image for OCR processing
input.FindTextRegion(); // Automatically detects the text region in the image
OcrResult result = ocr.Read(input); // Perform OCR on the detected text region
string resultText = result.Text; // Store the extracted text
using IronOcr; // Import IronOcr namespace

var ocr = new IronTesseract(); // Initialize IronTesseract object
using var input = new OcrInput(); // Create an OcrInput object to hold the image
input.LoadImage("/path/file.png"); // Load the image for OCR processing
input.FindTextRegion(); // Automatically detects the text region in the image
OcrResult result = ocr.Read(input); // Perform OCR on the detected text region
string resultText = result.Text; // Store the extracted text
Imports IronOcr ' Import IronOcr namespace

Private ocr = New IronTesseract() ' Initialize IronTesseract object
Private input = New OcrInput() ' Create an OcrInput object to hold the image
input.LoadImage("/path/file.png") ' Load the image for OCR processing
input.FindTextRegion() ' Automatically detects the text region in the image
Dim result As OcrResult = ocr.Read(input) ' Perform OCR on the detected text region
Dim resultText As String = result.Text ' Store the extracted text
$vbLabelText   $csharpLabel

此代碼使用 IronOCR 的 FindTextRegion() 方法在提取文本之前,自動檢測輸入圖像中對應於車輛註冊版的文字區域。

要了解有關如何在 IronOCR 中使用計算機視覺的更多詳細信息,請訪問:如何使用計算機視覺檢測文本

3. 從汽車圖像中提取細節

超出獨立的號牌圖像,IronOCR 使我們能夠通過特定檢測和提取號牌區域,從完整的車輛圖像中提取細節。 當我們需要處理包含整個車輛的圖像時,此功能特別有價值,允許我們將 OCR 努力集中於相關區域以提高效率和精確度。

要通過特定檢測和提取號牌區域,從完整的車輛圖像中提取細節,可以使用以下代碼:

using IronOcr; // Import IronOcr namespace

var ocr = new IronTesseract(); // Initialize IronTesseract object
using (var input = new OcrInput()) // Create an OcrInput object to hold the image
{
    var contentArea = new Rectangle(x: 365, y: 240, height: 80, width: 29); // Specify the region of interest
    input.LoadImage(@"path_to_car_image.jpg", contentArea); // Load the image for OCR processing
    var result = ocr.Read(input); // Perform OCR on the specified region
    Console.WriteLine(result.Text); // Output the extracted text
}
using IronOcr; // Import IronOcr namespace

var ocr = new IronTesseract(); // Initialize IronTesseract object
using (var input = new OcrInput()) // Create an OcrInput object to hold the image
{
    var contentArea = new Rectangle(x: 365, y: 240, height: 80, width: 29); // Specify the region of interest
    input.LoadImage(@"path_to_car_image.jpg", contentArea); // Load the image for OCR processing
    var result = ocr.Read(input); // Perform OCR on the specified region
    Console.WriteLine(result.Text); // Output the extracted text
}
Imports IronOcr ' Import IronOcr namespace

Private ocr = New IronTesseract() ' Initialize IronTesseract object
Using input = New OcrInput() ' Create an OcrInput object to hold the image
	Dim contentArea = New Rectangle(x:= 365, y:= 240, height:= 80, width:= 29) ' Specify the region of interest
	input.LoadImage("path_to_car_image.jpg", contentArea) ' Load the image for OCR processing
	Dim result = ocr.Read(input) ' Perform OCR on the specified region
	Console.WriteLine(result.Text) ' Output the extracted text
End Using
$vbLabelText   $csharpLabel

此代碼使用 Rectangle 指定汽車圖像中包含號牌的感興趣區域。 然後,IronOCR 從此指定區域提取文本,允許高效處理汽車圖像。

輸入圖像

如何在 C# 中執行車輛註冊 OCR:圖 7 - 汽車圖像輸入

輸出

如何在 C# 中執行車輛註冊 OCR:圖 8 - OCR 解決方案輸出

憑藉 IronOCR 對於獨立的號牌圖像和汽車圖像的支持,加上其與計算機視覺和人工智能的集成以進行准確的文本區域檢測,我們能夠實現從車輛註冊號牌中可靠且高效的信息提取。

有關IronOCR功能的更詳細信息,請訪問此文檔頁面。

結論

總之,IronOCR 為 OCR 任務提供了一個強大的解決方案,包括從圖像中提取車輛註冊版信息。 通過利用其先進功能和與 .NET 應用程序的無縫集成,開發人員可以簡化流程並提高依賴於 OCR 技術的各種應用程序的效率。 使用 IronOCR,從車輛註冊版中自動提取文本變得簡單易行,使企業和組織能在業務運營中實現更高的準確性和生產力。

IronOCR 提供一個免費試用,起價格為 $799。 請隨時下載並試用 IronOCR——這是一個增強您數據提取需求的寶貴工具!

常見問題解答

如何使用 OCR 在 C# 中從車輛註冊牌照中提取數據?

您可以使用 IronOCR 的綜合 .NET 庫從車輛註冊牌照中提取文本。通過利用 IronTesseract 類,您可以高效地閱讀和處理 C# 中的各種牌照格式。

什麼是自動車牌識別(ANPR),為何重要?

自動車牌識別(ANPR)是一項技術,用於自動捕獲和提取車輛註冊牌照中的數據。它在減少錯誤和提高執法及停車管理等應用效率方面至關重要。

IronOCR 如何使用計算機視覺提高 OCR 的準確性?

IronOCR 透過使用計算機視覺能力(如 FindTextRegion 方法),來提高 OCR 的準確性,自動檢測圖像中的文本區域,並集中 OCR 努力於這些區域。

IronOCR 是否可用於從完整車輛圖像中提取數據?

是的,IronOCR 可以從完整車輛圖像中檢測和提取車牌區域,使得處理和提取這些圖像中的相關信息更加輕鬆。

在 C# 項目中使用 IronOCR 的前提條件是什麼?

要在 C# 項目中使用 IronOCR,您需要 Visual Studio 2022、對 C# 編程有基本了解以及訪問 NuGet 包管理器以安裝 IronOCR。

如何在我的 Visual Studio 項目中安裝 IronOCR?

您可以在 NuGet 包管理器控制台中執行 Install-Package IronOcr 或在「管理 NuGet 包」部分搜索 IronOCR 並點擊「安裝」,以安裝 IronOCR。

IronOCR 是否有試用版?

是的,IronOCR 提供免費試用版本,讓您測試其特性和功能以滿足您的數據提取需求。

在 C# 中使用 IronOCR 進行 OCR 任務的優勢有哪些?

IronOCR 提供精確的圖像文本提取,多語言支持,先進的圖像處理和與 .NET 應用無縫集成,使其成為 C# 中 OCR 任務的強大工具。

如何提高從車輛註冊中提取數據的 OCR 準確性?

為提高 OCR 準確性,您可以使用 IronOCR 的 FindTextRegion 方法專注於相關文本區域,並在處理前提高輸入圖像的質量。

使用 IronOCR 對車輛註冊牌照進行 OCR 的步驟有哪些?

步驟包括安裝 IronOCR、使用 OcrInput.LoadImage 加載圖像、應用 FindTextRegion 進行文本區域檢測,並使用 Read 方法提取數據。

Kannaopat Udonpant
軟體工程師
在成為软件工程師之前,Kannapat 從日本北海道大學完成了環境資源博士學位。在追逐學位期间,Kannapat 還成為了生產工程系一部份——汽車机器人实验室的成員。2022 年,他利用他的 C# 技能加入 Iron Software 的工程團隊, 專注於 IronPDF。Kannapat 珍惜他的工作,因为他直接向编写大部分 IronPDF 使用的代码的开发者学习。除了同行学习,Kannapat 还喜欢在 Iron Software 工作的社交十环。当他不编写代码或文档时,Kannapat 通常在他的 PS5 上打游戏或重看《The Last of Us》。