Распознавание 2D штрих-кодов с пространственными искажениями в .NET
Категория: Штрих-коды; .NET
6 мая 2020


/// <summary>
/// Распознает 2D матричные штрих-коды (Aztec, QR Code и Han Xin Code) с пространственными изображениями.
/// </summary>
public void Recognize2dBarcodeWithSpatialDistortions()
{
// создать распознаватель штрих-кодов
using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
{
// указать, что распознаватель должен искать штрих-коды Aztec, QR и Han Xin Code
reader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.Aztec |
Vintasoft.Barcode.BarcodeType.QR |
Vintasoft.Barcode.BarcodeType.HanXinCode;
// указать, что распознаватель должен искать только горизонтальные и вертикальные штрих-коды
reader.Settings.ScanDirection = Vintasoft.Barcode.ScanDirection.Horizontal | Vintasoft.Barcode.ScanDirection.Vertical;
// распознать штрих-коды в изображении
Vintasoft.Barcode.IBarcodeInfo[] barcodeInfos = reader.ReadBarcodes("barcodes.png");
// если штрих-коды не обнаружены
if (barcodeInfos.Length == 0)
{
System.Console.WriteLine("Barcodes are not found.");
}
// если штрих-коды обнаружены
else
{
// получить информацию о распознанных штрих-кодах
System.Console.WriteLine(string.Format("{0} barcode(s) found:", barcodeInfos.Length));
System.Console.WriteLine();
for (int i = 0; i < barcodeInfos.Length; i++)
{
Vintasoft.Barcode.IBarcodeInfo barcodeInfo = barcodeInfos[i];
System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, barcodeInfo.BarcodeType));
System.Console.WriteLine(string.Format("Value: {0}", barcodeInfo.Value));
System.Console.WriteLine(string.Format("Region: {0}", barcodeInfo.Region));
System.Console.WriteLine();
}
}
}
}





