In This Topic
Provides information about barcode layout on an image.
Object Model
Syntax
Remarks
If image contains several barcodes, information about approximate location of barcodes in image can greatly increase the barcode recognition performance.
Example
This example shows how to provide information about barcode locations on an image to barcode reader.
Imports Vintasoft.Barcode
Imports Vintasoft.Barcode.BarcodeInfo
Imports Vintasoft.Barcode.SymbologySubsets
Imports Vintasoft.Primitives
''' <summary>
''' Test that shows how to provide information about barcode locations in an image to barcode reader.
''' </summary>
Public Class BarcodeLayoutInfoExample
''' <summary>
''' Runs the test.
''' </summary>
Public Shared Sub Test()
ReadBarcodes("BarcodeLayoutInfoTest1.png", "BarcodeLayoutInfoTest2.png")
End Sub
''' <summary>
''' Reads barcodes from images, which are stored in files.
''' </summary>
Public Shared Sub ReadBarcodes(ParamArray filenames As String())
Dim barcodeLayoutInfo As New BarcodeLayoutInfo()
' add information about EAN13 barcode that is located in the left-bottom part of an image
barcodeLayoutInfo.AddBarcodeInfoRelative(BarcodeType.EAN13, New VintasoftRect(0, 0.4, 0.3, 0.6))
' add information about DataMatrix barcode that is located in the center of an image
barcodeLayoutInfo.AddBarcodeInfoRelative(BarcodeType.DataMatrix, New VintasoftRect(0.25, 0.25, 0.5, 0.5))
' create barcode reader
Using reader As New BarcodeReader()
' set barcode layout info
reader.BarcodeRegionDetectors = New BarcodeRegionDetectors(barcodeLayoutInfo)
' specify that reader must search for EAN13 and GS1 DataMatrix barcodes
reader.Settings.ScanBarcodeTypes = BarcodeType.EAN13
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.GS1DataMatrix)
' for each filename
For Each filename As String In filenames
Console.Write(String.Format("{0}: ", filename))
' read barcodes
Dim infos As IBarcodeInfo() = reader.ReadBarcodes(filename)
' show barcode recognition results
If infos.Length = 0 Then
Console.WriteLine("No barcodes found.")
Else
Console.WriteLine(String.Format("{0} barcodes found ({1}ms):", infos.Length, reader.RecognizeTime.TotalMilliseconds))
For i As Integer = 0 To infos.Length - 1
Dim info As IBarcodeInfo = infos(i)
Dim name As String = info.BarcodeType.ToString()
If TypeOf info Is BarcodeSubsetInfo Then
name = DirectCast(info, BarcodeSubsetInfo).BarcodeSubset.Name
End If
Console.WriteLine(String.Format("{0}: [{1}] {2}", i + 1, name, info.Value))
Next
Console.WriteLine()
End If
Next
End Using
End Sub
End Class
using System;
using Vintasoft.Barcode;
using Vintasoft.Barcode.BarcodeInfo;
using Vintasoft.Barcode.SymbologySubsets;
using Vintasoft.Primitives;
/// <summary>
/// Test that shows how to provide information about barcode locations in an image to barcode reader.
/// </summary>
public class BarcodeLayoutInfoExample
{
/// <summary>
/// Runs the test.
/// </summary>
public static void Test()
{
ReadBarcodes("BarcodeLayoutInfoTest1.png", "BarcodeLayoutInfoTest2.png");
}
/// <summary>
/// Reads barcodes from images, which are stored in files.
/// </summary>
public static void ReadBarcodes(params string[] filenames)
{
BarcodeLayoutInfo barcodeLayoutInfo = new BarcodeLayoutInfo();
// add information about EAN13 barcode that is located in the left-bottom part of an image
barcodeLayoutInfo.AddBarcodeInfoRelative(BarcodeType.EAN13, new VintasoftRect(0, 0.4, 0.3, 0.6));
// add information about DataMatrix barcode that is located in the center of an image
barcodeLayoutInfo.AddBarcodeInfoRelative(BarcodeType.DataMatrix, new VintasoftRect(0.25, 0.25, 0.5, 0.5));
// create barcode reader
using (BarcodeReader reader = new BarcodeReader())
{
// set barcode layout info
reader.BarcodeRegionDetectors = new BarcodeRegionDetectors(barcodeLayoutInfo);
// specify that reader must search for EAN13 and GS1 DataMatrix barcodes
reader.Settings.ScanBarcodeTypes = BarcodeType.EAN13;
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.GS1DataMatrix);
// for each filename
foreach (string filename in filenames)
{
Console.Write(string.Format("{0}: ", filename));
// read barcodes
IBarcodeInfo[] infos = reader.ReadBarcodes(filename);
// show barcode recognition results
if (infos.Length == 0)
{
Console.WriteLine("No barcodes found.");
}
else
{
Console.WriteLine(string.Format("{0} barcodes found ({1}ms):", infos.Length, reader.RecognizeTime.TotalMilliseconds));
for (int i = 0; i < infos.Length; i++)
{
IBarcodeInfo info = infos[i];
string name = info.BarcodeType.ToString();
if (info is BarcodeSubsetInfo)
name = ((BarcodeSubsetInfo)info).BarcodeSubset.Name;
Console.WriteLine(string.Format("{0}: [{1}] {2}", i + 1, name, info.Value));
}
Console.WriteLine();
}
}
}
}
}
Inheritance Hierarchy
System.Object
 Vintasoft.Barcode.BarcodeRegionDetector
   Vintasoft.Barcode.BarcodeLayoutInfo
Requirements
Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also