在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
車牌識別已成為許多行業中不可或缺的工具,從交通管理和停車系統到執法和收費解決方案都依賴它。 通過利用光學字元識別(OCR)技術,開發人員可以有效地從圖像中提取文本,自動化識別車牌的過程。 在本教程中,我們將演示如何使用IronOCR,一個功能強大的 C# OCR 庫,來精確地從圖像中讀取車牌。 IronOCR 與用於計算機視覺任務的 OpenCV 原始碼無縫整合,提供一個強大的解決方案,即使是從複雜或噪聲影像來源中也能識別文字。 無論您是在處理清晰的車牌圖像還是完整的車輛照片,本指南將引導您使用現代OCR技術建立可靠的車牌識別系統的步驟。
將車牌圖像導入新的 OcrImageInput 實例中
在 C# 中應用影像濾鏡以改善文字擷取
透過在照片中指定車牌區域來提高識別速度
IronOCR 是一個基於 Tesseract OCR 引擎的 C# OCR 函式庫,專門為 .NET 應用中的文本識別專案提供高準確性和效率而設計。 IronOCR 對於處理噪聲或低質量圖像非常理想,它包含強大的圖像預處理功能,如自動降噪和灰度轉換,這些功能可以增強文本提取的清晰度。
IronOCR 的一些突出功能包括:
靈活的輸入選項:支持多頁文檔和可調整的區域,讓開發人員可以將OCR處理集中於選定的區域,以獲得更快且更具針對性的結果。
憑藉這些功能,IronOCR 是一個強大的解決方案,適用於構建需要準確性、靈活性以及易於與其他計算機視覺工具集成的 OCR 應用程序。
首先,打開 Visual Studio,然後選擇「建立新專案」。 這將帶您進入一個頁面,您可以在那裡選擇要構建的專案類型(在我們的情況下,我們將製作一個控制台應用程式)。 選擇所需的應用程式類型,然後點選“下一步”。
現在,請為您的專案命名並選擇儲存位置。
最後,選擇您的目標 .NET 框架,然後按一下「Create」按鈕。 這將創建項目,如下所示。
下一步是安裝IronOCR庫,以便我們可以開始處理車牌。
要在您的 C# 專案中開始使用 IronOCR,您需要從 NuGet 安裝 IronOCR 套件。 IronOCR 與 .NET Framework 和 .NET Core 兼容,使其易於整合到各種 .NET 應用程式中。
在 Visual Studio 中,導航到 工具 > NuGet 套件管理員 > 套件管理器主控台。
在封裝管理器主控台中輸入以下命令:
Install-Package IronOcr
Install-Package IronOcr
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package IronOcr
此命令將安裝 IronOCR 庫,包括在您的專案中運行 OCR 功能所需的所有依賴項。 由於我們的應用程式需要使用電腦視覺的進階功能,如車牌識別,您也可以這樣安裝可選的IronOcr.ComputerVision.Windows套件:
Install-Package IronOcr.ComputerVision.Windows
Install-Package IronOcr.ComputerVision.Windows
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package IronOcr.ComputerVision.Windows
並確保您已安裝 IronOcr.Extensions.AdvancedScan 擴展,以便您可以使用其強大的 ReadLicensePlate 方法:
Install-Package IronOcr.Extensions.AdvancedScan
Install-Package IronOcr.Extensions.AdvancedScan
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package IronOcr.Extensions.AdvancedScan
或者,您可以使用工具 > NuGet 套件管理員 > 管理解決方案的 NuGet 套件來安裝套件,並搜尋您需要的套件:
最後,我們必須在程式碼的頂部添加必要的匯入和使用語句:
using IronOcr;
using IronOcr;
Imports IronOcr
在本節中,我們將使用IronOCR創建一個程序來讀取車牌,這是一個在從圖像中提取文字方面表現卓越的Tesseract OCR引擎。 為了實現車輛檢測,我們可能還需要整合其他機器學習庫。 值得注意的是,IronOCR 與 OpenCV 整合,這是一個領先的開源計算機視覺庫,使我們能夠執行物體檢測任務,比如識別車輛和車牌。
我們將使用以下車牌:
接下來,新增以下程式碼來對車牌進行光學字符識別(OCR):
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrImageInput("licensePlate.jpeg"))
{
// Fixing the digital noise and making the image easier to read
input.DeNoise();
input.ToGrayScale();
// Using the OcrLicensePlateResult and ReadLicensePlate methods to read the license plate information and store it for further use
OcrLicensePlateResult result = ocr.ReadLicensePlate(input);
// Saving the license plate text to a string variable
string output = result.Text;
// Outputting the license plate text to the console
Console.WriteLine(output);
}
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrImageInput("licensePlate.jpeg"))
{
// Fixing the digital noise and making the image easier to read
input.DeNoise();
input.ToGrayScale();
// Using the OcrLicensePlateResult and ReadLicensePlate methods to read the license plate information and store it for further use
OcrLicensePlateResult result = ocr.ReadLicensePlate(input);
// Saving the license plate text to a string variable
string output = result.Text;
// Outputting the license plate text to the console
Console.WriteLine(output);
}
Imports IronOcr
Private ocr = New IronTesseract()
Using input = New OcrImageInput("licensePlate.jpeg")
' Fixing the digital noise and making the image easier to read
input.DeNoise()
input.ToGrayScale()
' Using the OcrLicensePlateResult and ReadLicensePlate methods to read the license plate information and store it for further use
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(input)
' Saving the license plate text to a string variable
Dim output As String = result.Text
' Outputting the license plate text to the console
Console.WriteLine(output)
End Using
程式碼解析:
影像預處理:
如果我們有一整輛汽車的圖片而不僅僅是車牌,我們可以指定一個矩形區域來關注車牌區域。 我們可以使用System.Drawing.Rectangle來定義此區域的像素。
我們將使用下面的圖像檔作為範例:
透過指定關注的區域,我們提升了處理速度並避免提取不必要的文本。
using IronOcr;
using System.Drawing;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
var contentArea = new Rectangle(x: 252, y: 282, width: 148, height: 47);
input.LoadImage("CarPlate.jpeg", contentArea);
OcrLicensePlateResult result = ocr.ReadLicensePlate(input);
Console.WriteLine(result.Text);
}
using IronOcr;
using System.Drawing;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
var contentArea = new Rectangle(x: 252, y: 282, width: 148, height: 47);
input.LoadImage("CarPlate.jpeg", contentArea);
OcrLicensePlateResult result = ocr.ReadLicensePlate(input);
Console.WriteLine(result.Text);
}
Imports IronOcr
Imports System.Drawing
Private ocr = New IronTesseract()
Using input = New OcrInput()
Dim contentArea = New Rectangle(x:= 252, y:= 282, width:= 148, height:= 47)
input.LoadImage("CarPlate.jpeg", contentArea)
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(input)
Console.WriteLine(result.Text)
End Using
程式碼解析:
IronOCR 利用 OpenCV 來識別圖像中的文本區域,採用多種影像處理技術。 此功能使程式能夠通過定位影像中的文字區域來偵測車牌,然後利用 Tesseract 來讀取這些區域。
要啟用車牌檢測模型,請透過套件管理器主控台安裝所需的套件:
var ocr = new IronTesseract();
using (var input = new OcrImageInput("CarPlate.jpeg"))
{
input.FindTextRegion();
OcrLicensePlateResult result = ocr.ReadLicensePlate(input);
Console.WriteLine(result.Text);
}
var ocr = new IronTesseract();
using (var input = new OcrImageInput("CarPlate.jpeg"))
{
input.FindTextRegion();
OcrLicensePlateResult result = ocr.ReadLicensePlate(input);
Console.WriteLine(result.Text);
}
Dim ocr = New IronTesseract()
Using input = New OcrImageInput("CarPlate.jpeg")
input.FindTextRegion()
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(input)
Console.WriteLine(result.Text)
End Using
程式碼解析:
對於那些想親自試用IronOCR的人,IronOCR提供了免費試用,這讓您可以訪問其提供的所有工具,這意味著您可以在購買許可證之前,在您自己的專案中嘗試使用它們。 一旦您的免費試用期結束,IronOCR 授權起價僅為 $749,即可獲得 lite 授權。 它還提供可選的附加元件,需額外付費,例如免版稅的重新分發覆蓋以及不間斷的支持和持續的產品更新。
除此之外,如果您發現自己需要使用更多的 IronSoftware 產品,不僅僅是 IronOCR,例如,IronPDF 用於處理 PDF 任務或 IronWord 用於處理 Word 文件,那麼 IronSoftware 還提供 Iron Suite,這是一個以優惠價格獲取完整工具組的好方法。
在本指南中,我們探討了如何使用IronOCR在 C# 中構建可靠的車牌識別系統。 IronOCR 擁有強大的文字提取功能,並整合了 OpenCV,為需要從車輛圖像中準確識別文字的應用程序提供了一個高效且易於使用的解決方案。 從圖像預處理到設置特定檢測區域,IronOCR 使用專為噪音大或複雜圖像(如交通和監控錄像中的車牌)設計的工具來簡化 OCR 過程。
無論您是在開發交通監控、停車執法,或是任何需要自動車牌識別的應用程式,IronOCR 提供了一個全面的程式庫,可以無縫整合到 .NET 環境中。 通過遵循這些步驟,您能夠部署搭載光學字符識別技術的解決方案,以提高各種現實場景的效率和準確性。 透過區域選擇和噪點消除等附加功能,IronOCR 確保您的車牌識別任務優化以達到最佳可能結果。