如何使用IronOCR读取车牌
在管理大量车辆图像时,人工读取车牌耗时且容易出错。 使用像 IronOCR 这样的工具自动化此过程可以提供更高效、准确的解决方案。 IronOCR的ReadLicensePlate
方法可以通过编程从图像中提取车牌号码,节省大量时间并提高数据准确性。
在本指南中,我们将演示如何使用IronOCR进行车牌识别,提供示例和可自定义的配置,使这一过程变得流畅。 通过利用这些方法,开发人员可以自动识别车牌,使停车管理、收费收集或安全监控等任务更加高效。
如何使用IronOCR读取车牌
- 下载用于读取车牌的C#库
- 导入车牌图像以进行处理
- 确保文档只包含车牌图像,不含页眉或页脚
- 使用
读取许可证号
从图像中提取数据的方法 - 访问OcrLicensePlateResult查看并操作提取的许可证数据的属性
立即在您的项目中开始使用IronOCR,并享受免费试用。
要使用此功能,您还必须安装IronOcr.Extension.AdvancedScan包装
阅读车牌示例
要在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)
输出
请注意,我们必须首先将图像导入为 OcrInput
,以正确传递参数给 ReadLicensePlate
方法。
从控制台输出可以看出,提取的文本与输入图像中显示的车牌号和州相匹配。
从 OCR 输入中提取的文本。
Confidence:一个“双精度”属性,指示每个字符平均统计准确性的置信度,其中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)
输出
如您所见,输出与上述车牌匹配,并且图像中车牌的确切矩形区域也被正确提取。
这种方法经过优化,仅用于识别单个车牌,并且能够在库存图像中进行搜索。