using IronBarCode;// Format-constrained read with false-positive removal.// Limit the decoder to EAN-13 and Code128; checksums are// validated automatically and failures are silently discarded.var options = new BarcodeReaderOptions{ExpectBarcodeTypes = BarcodeEncoding.EAN13 | BarcodeEncoding.Code128,RemoveFalsePositive = true,Speed = ReadingSpeed.Balanced};BarcodeResults results = BarcodeReader.Read("label.png", options);
using IronBarCode;
// Format-constrained read with false-positive removal.
// Limit the decoder to EAN-13 and Code128; checksums are
// validated automatically and failures are silently discarded.
var options = new BarcodeReaderOptions
{
ExpectBarcodeTypes = BarcodeEncoding.EAN13 | BarcodeEncoding.Code128,
RemoveFalsePositive = true,
Speed = ReadingSpeed.Balanced
};
BarcodeResults results = BarcodeReader.Read("label.png", options);
ImportsIronBarCode' Format-constrained read with false-positive removal.' Limit the decoder to EAN-13 and Code128; checksums are' validated automatically and failures are silently discarded.Dim options As New BarcodeReaderOptionsWith { .ExpectBarcodeTypes = BarcodeEncoding.EAN13OrBarcodeEncoding.Code128, .RemoveFalsePositive = True, .Speed = ReadingSpeed.Balanced}Dim results AsBarcodeResults = BarcodeReader.Read("label.png", options)
Imports IronBarCode
' Format-constrained read with false-positive removal.
' Limit the decoder to EAN-13 and Code128; checksums are
' validated automatically and failures are silently discarded.
Dim options As New BarcodeReaderOptions With {
.ExpectBarcodeTypes = BarcodeEncoding.EAN13 Or BarcodeEncoding.Code128,
.RemoveFalsePositive = True,
.Speed = ReadingSpeed.Balanced
}
Dim results As BarcodeResults = BarcodeReader.Read("label.png", options)
using IronBarCode;// Constrain reads to 1D formats and enable secondary verification.// ConfidenceThreshold rejects decodes where the ML detector falls below 85%,// acting as a quality gate for optional-checksum symbologies like Code39.var options = new BarcodeReaderOptions{ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,RemoveFalsePositive = true,ConfidenceThreshold = 0.85,Speed = ReadingSpeed.Detailed};BarcodeResults results = BarcodeReader.Read("warehouse-rack.png", options);foreach (BarcodeResult result in results){ // Each result has passed checksum validation (mandatory formats) // and the 85% confidence threshold, so no additional filtering is needed.Console.WriteLine($"[{result.BarcodeType}] {result.Value} page={result.PageNumber}");}if (results.Count == 0){Console.Error.WriteLine("No valid barcodes found. Possible causes:");Console.Error.WriteLine(" - Check digit mismatch (barcode silently rejected)");Console.Error.WriteLine(" - Confidence below 85% threshold");Console.Error.WriteLine(" - Format not in ExpectBarcodeTypes");}
using IronBarCode;
// Constrain reads to 1D formats and enable secondary verification.
// ConfidenceThreshold rejects decodes where the ML detector falls below 85%,
// acting as a quality gate for optional-checksum symbologies like Code39.
var options = new BarcodeReaderOptions
{
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
RemoveFalsePositive = true,
ConfidenceThreshold = 0.85,
Speed = ReadingSpeed.Detailed
};
BarcodeResults results = BarcodeReader.Read("warehouse-rack.png", options);
foreach (BarcodeResult result in results)
{
// Each result has passed checksum validation (mandatory formats)
// and the 85% confidence threshold, so no additional filtering is needed.
Console.WriteLine($"[{result.BarcodeType}] {result.Value} page={result.PageNumber}");
}
if (results.Count == 0)
{
Console.Error.WriteLine("No valid barcodes found. Possible causes:");
Console.Error.WriteLine(" - Check digit mismatch (barcode silently rejected)");
Console.Error.WriteLine(" - Confidence below 85% threshold");
Console.Error.WriteLine(" - Format not in ExpectBarcodeTypes");
}
ImportsIronBarCode' Constrain reads to 1D formats and enable secondary verification.' ConfidenceThreshold rejects decodes where the ML detector falls below 85%,' acting as a quality gate for optional-checksum symbologies like Code39.Dim options As New BarcodeReaderOptionsWith { .ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional, .RemoveFalsePositive = True, .ConfidenceThreshold = 0.85, .Speed = ReadingSpeed.Detailed}Dim results AsBarcodeResults = BarcodeReader.Read("warehouse-rack.png", options)For Each result AsBarcodeResultIn results ' Each result has passed checksum validation (mandatory formats) ' and the 85% confidence threshold, so no additional filtering is needed.Console.WriteLine($"[{result.BarcodeType}] {result.Value} page={result.PageNumber}")NextIf results.Count = 0 ThenConsole.Error.WriteLine("No valid barcodes found. Possible causes:")Console.Error.WriteLine(" - Check digit mismatch (barcode silently rejected)")Console.Error.WriteLine(" - Confidence below 85% threshold")Console.Error.WriteLine(" - Format not in ExpectBarcodeTypes")End If
Imports IronBarCode
' Constrain reads to 1D formats and enable secondary verification.
' ConfidenceThreshold rejects decodes where the ML detector falls below 85%,
' acting as a quality gate for optional-checksum symbologies like Code39.
Dim options As New BarcodeReaderOptions With {
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
.RemoveFalsePositive = True,
.ConfidenceThreshold = 0.85,
.Speed = ReadingSpeed.Detailed
}
Dim results As BarcodeResults = BarcodeReader.Read("warehouse-rack.png", options)
For Each result As BarcodeResult In results
' Each result has passed checksum validation (mandatory formats)
' and the 85% confidence threshold, so no additional filtering is needed.
Console.WriteLine($"[{result.BarcodeType}] {result.Value} page={result.PageNumber}")
Next
If results.Count = 0 Then
Console.Error.WriteLine("No valid barcodes found. Possible causes:")
Console.Error.WriteLine(" - Check digit mismatch (barcode silently rejected)")
Console.Error.WriteLine(" - Confidence below 85% threshold")
Console.Error.WriteLine(" - Format not in ExpectBarcodeTypes")
End If
using IronBarCode;// Constrained read: only Code128 barcodes are returned.// Faster because the reader skips all other format detectors.var constrainedOptions = new BarcodeReaderOptions{ExpectBarcodeTypes = BarcodeEncoding.Code128,Speed = ReadingSpeed.Faster,ExpectMultipleBarcodes = false};// Broad read: all supported formats are scanned.// Useful for verification or when the image format is unknown.var broadOptions = new BarcodeReaderOptions{ExpectBarcodeTypes = BarcodeEncoding.All,Speed = ReadingSpeed.Detailed,ExpectMultipleBarcodes = true};string imagePath = "shipping-label.png";BarcodeResults constrained = BarcodeReader.Read(imagePath, constrainedOptions);Console.WriteLine($"Constrained: {constrained.Count} Code128 barcode(s) found");BarcodeResults broad = BarcodeReader.Read(imagePath, broadOptions);Console.WriteLine($"Broad: {broad.Count} barcode(s) found across all formats");foreach (BarcodeResult result in broad){Console.WriteLine($" [{result.BarcodeType}] {result.Value}");}
using IronBarCode;
// Constrained read: only Code128 barcodes are returned.
// Faster because the reader skips all other format detectors.
var constrainedOptions = new BarcodeReaderOptions
{
ExpectBarcodeTypes = BarcodeEncoding.Code128,
Speed = ReadingSpeed.Faster,
ExpectMultipleBarcodes = false
};
// Broad read: all supported formats are scanned.
// Useful for verification or when the image format is unknown.
var broadOptions = new BarcodeReaderOptions
{
ExpectBarcodeTypes = BarcodeEncoding.All,
Speed = ReadingSpeed.Detailed,
ExpectMultipleBarcodes = true
};
string imagePath = "shipping-label.png";
BarcodeResults constrained = BarcodeReader.Read(imagePath, constrainedOptions);
Console.WriteLine($"Constrained: {constrained.Count} Code128 barcode(s) found");
BarcodeResults broad = BarcodeReader.Read(imagePath, broadOptions);
Console.WriteLine($"Broad: {broad.Count} barcode(s) found across all formats");
foreach (BarcodeResult result in broad)
{
Console.WriteLine($" [{result.BarcodeType}] {result.Value}");
}
ImportsIronBarCode' Constrained read: only Code128 barcodes are returned.' Faster because the reader skips all other format detectors.Dim constrainedOptions As New BarcodeReaderOptionsWith { .ExpectBarcodeTypes = BarcodeEncoding.Code128, .Speed = ReadingSpeed.Faster, .ExpectMultipleBarcodes = False}' Broad read: all supported formats are scanned.' Useful for verification or when the image format is unknown.Dim broadOptions As New BarcodeReaderOptionsWith { .ExpectBarcodeTypes = BarcodeEncoding.All, .Speed = ReadingSpeed.Detailed, .ExpectMultipleBarcodes = True}Dim imagePath AsString = "shipping-label.png"Dim constrained AsBarcodeResults = BarcodeReader.Read(imagePath, constrainedOptions)Console.WriteLine($"Constrained: {constrained.Count} Code128 barcode(s) found")Dim broad AsBarcodeResults = BarcodeReader.Read(imagePath, broadOptions)Console.WriteLine($"Broad: {broad.Count} barcode(s) found across all formats")For Each result AsBarcodeResultIn broadConsole.WriteLine($" [{result.BarcodeType}] {result.Value}")Next
Imports IronBarCode
' Constrained read: only Code128 barcodes are returned.
' Faster because the reader skips all other format detectors.
Dim constrainedOptions As New BarcodeReaderOptions With {
.ExpectBarcodeTypes = BarcodeEncoding.Code128,
.Speed = ReadingSpeed.Faster,
.ExpectMultipleBarcodes = False
}
' Broad read: all supported formats are scanned.
' Useful for verification or when the image format is unknown.
Dim broadOptions As New BarcodeReaderOptions With {
.ExpectBarcodeTypes = BarcodeEncoding.All,
.Speed = ReadingSpeed.Detailed,
.ExpectMultipleBarcodes = True
}
Dim imagePath As String = "shipping-label.png"
Dim constrained As BarcodeResults = BarcodeReader.Read(imagePath, constrainedOptions)
Console.WriteLine($"Constrained: {constrained.Count} Code128 barcode(s) found")
Dim broad As BarcodeResults = BarcodeReader.Read(imagePath, broadOptions)
Console.WriteLine($"Broad: {broad.Count} barcode(s) found across all formats")
For Each result As BarcodeResult In broad
Console.WriteLine($" [{result.BarcodeType}] {result.Value}")
Next
using IronBarCode;// Combine multiple format flags with | to scan for more than one symbology// in a single pass. Each BarcodeResult.BarcodeType identifies which format// was decoded, enabling downstream routing logic per symbology.var options = new BarcodeReaderOptions{ExpectBarcodeTypes = BarcodeEncoding.EAN13 | BarcodeEncoding.Code128,ExpectMultipleBarcodes = true};
using IronBarCode;
// Combine multiple format flags with | to scan for more than one symbology
// in a single pass. Each BarcodeResult.BarcodeType identifies which format
// was decoded, enabling downstream routing logic per symbology.
var options = new BarcodeReaderOptions
{
ExpectBarcodeTypes = BarcodeEncoding.EAN13 | BarcodeEncoding.Code128,
ExpectMultipleBarcodes = true
};
ImportsIronBarCode' Combine multiple format flags with Or to scan for more than one symbology' in a single pass. Each BarcodeResult.BarcodeType identifies which format' was decoded, enabling downstream routing logic per symbology.Dim options As New BarcodeReaderOptionsWith { .ExpectBarcodeTypes = BarcodeEncoding.EAN13OrBarcodeEncoding.Code128, .ExpectMultipleBarcodes = True}
Imports IronBarCode
' Combine multiple format flags with Or to scan for more than one symbology
' in a single pass. Each BarcodeResult.BarcodeType identifies which format
' was decoded, enabling downstream routing logic per symbology.
Dim options As New BarcodeReaderOptions With {
.ExpectBarcodeTypes = BarcodeEncoding.EAN13 Or BarcodeEncoding.Code128,
.ExpectMultipleBarcodes = True
}
using IronBarCode;// Layered validation for retail POS: EAN-13, UPC-A, and UPC-E only.// Each property adds a distinct filter to the read pipeline.var options = new BarcodeReaderOptions{ // Layer 1: format constraint, accept only retail symbologiesExpectBarcodeTypes = BarcodeEncoding.EAN13 | BarcodeEncoding.UPCA | BarcodeEncoding.UPCE, // Layer 2: confidence threshold, reject decodes below 80%ConfidenceThreshold = 0.8, // Layer 3: false-positive removal, runs a secondary verification passRemoveFalsePositive = true,Speed = ReadingSpeed.Balanced,ExpectMultipleBarcodes = false, // Require 3 agreeing scan lines to reduce phantom reads from noisy imagesMinScanLines = 3};string[] scanFiles = Directory.GetFiles("pos-scans/", "*.png");foreach (string file in scanFiles){ BarcodeResults results = BarcodeReader.Read(file, options); if (results.Count == 0) { // No barcode passed all validation layersConsole.Error.WriteLine($"REJECT {Path.GetFileName(file)}: " + "no valid EAN-13/UPC barcode (checksum, confidence, or format mismatch)"); continue; } BarcodeResult primary = results.First(); // Post-read assertion: verify the decoded format matches expectations. // ExpectBarcodeTypes already constrains the reader; this check documents // intent and surfaces unexpected results during future changes. if (primary.BarcodeType != BarcodeEncoding.EAN13 && primary.BarcodeType != BarcodeEncoding.UPCA && primary.BarcodeType != BarcodeEncoding.UPCE) {Console.Error.WriteLine($"UNEXPECTED FORMAT {Path.GetFileName(file)}: " + $"got {primary.BarcodeType}, expected EAN-13/UPC"); continue; }Console.WriteLine($"OK {Path.GetFileName(file)}: [{primary.BarcodeType}] {primary.Value}");}
using IronBarCode;
// Layered validation for retail POS: EAN-13, UPC-A, and UPC-E only.
// Each property adds a distinct filter to the read pipeline.
var options = new BarcodeReaderOptions
{
// Layer 1: format constraint, accept only retail symbologies
ExpectBarcodeTypes = BarcodeEncoding.EAN13 | BarcodeEncoding.UPCA | BarcodeEncoding.UPCE,
// Layer 2: confidence threshold, reject decodes below 80%
ConfidenceThreshold = 0.8,
// Layer 3: false-positive removal, runs a secondary verification pass
RemoveFalsePositive = true,
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = false,
// Require 3 agreeing scan lines to reduce phantom reads from noisy images
MinScanLines = 3
};
string[] scanFiles = Directory.GetFiles("pos-scans/", "*.png");
foreach (string file in scanFiles)
{
BarcodeResults results = BarcodeReader.Read(file, options);
if (results.Count == 0)
{
// No barcode passed all validation layers
Console.Error.WriteLine($"REJECT {Path.GetFileName(file)}: "
+ "no valid EAN-13/UPC barcode (checksum, confidence, or format mismatch)");
continue;
}
BarcodeResult primary = results.First();
// Post-read assertion: verify the decoded format matches expectations.
// ExpectBarcodeTypes already constrains the reader; this check documents
// intent and surfaces unexpected results during future changes.
if (primary.BarcodeType != BarcodeEncoding.EAN13
&& primary.BarcodeType != BarcodeEncoding.UPCA
&& primary.BarcodeType != BarcodeEncoding.UPCE)
{
Console.Error.WriteLine($"UNEXPECTED FORMAT {Path.GetFileName(file)}: "
+ $"got {primary.BarcodeType}, expected EAN-13/UPC");
continue;
}
Console.WriteLine($"OK {Path.GetFileName(file)}: [{primary.BarcodeType}] {primary.Value}");
}
ImportsIronBarCodeImportsSystem.IO' Layered validation for retail POS: EAN-13, UPC-A, and UPC-E only.' Each property adds a distinct filter to the read pipeline.Dim options As New BarcodeReaderOptionsWith { ' Layer 1: format constraint, accept only retail symbologies .ExpectBarcodeTypes = BarcodeEncoding.EAN13OrBarcodeEncoding.UPCAOrBarcodeEncoding.UPCE, ' Layer 2: confidence threshold, reject decodes below 80% .ConfidenceThreshold = 0.8, ' Layer 3: false-positive removal, runs a secondary verification pass .RemoveFalsePositive = True, .Speed = ReadingSpeed.Balanced, .ExpectMultipleBarcodes = False, ' Require 3 agreeing scan lines to reduce phantom reads from noisy images .MinScanLines = 3}Dim scanFiles AsString() = Directory.GetFiles("pos-scans/", "*.png")For Each file AsStringIn scanFiles Dim results AsBarcodeResults = BarcodeReader.Read(file, options) If results.Count = 0 Then ' No barcode passed all validation layersConsole.Error.WriteLine($"REJECT {Path.GetFileName(file)}: " & "no valid EAN-13/UPC barcode (checksum, confidence, or format mismatch)") Continue For End If Dim primary AsBarcodeResult = results.First() ' Post-read assertion: verify the decoded format matches expectations. ' ExpectBarcodeTypes already constrains the reader; this check documents ' intent and surfaces unexpected results during future changes. If primary.BarcodeType <> BarcodeEncoding.EAN13AndAlso primary.BarcodeType <> BarcodeEncoding.UPCAAndAlso primary.BarcodeType <> BarcodeEncoding.UPCEThenConsole.Error.WriteLine($"UNEXPECTED FORMAT {Path.GetFileName(file)}: " & $"got {primary.BarcodeType}, expected EAN-13/UPC") Continue For End IfConsole.WriteLine($"OK {Path.GetFileName(file)}: [{primary.BarcodeType}] {primary.Value}")Next
Imports IronBarCode
Imports System.IO
' Layered validation for retail POS: EAN-13, UPC-A, and UPC-E only.
' Each property adds a distinct filter to the read pipeline.
Dim options As New BarcodeReaderOptions With {
' Layer 1: format constraint, accept only retail symbologies
.ExpectBarcodeTypes = BarcodeEncoding.EAN13 Or BarcodeEncoding.UPCA Or BarcodeEncoding.UPCE,
' Layer 2: confidence threshold, reject decodes below 80%
.ConfidenceThreshold = 0.8,
' Layer 3: false-positive removal, runs a secondary verification pass
.RemoveFalsePositive = True,
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = False,
' Require 3 agreeing scan lines to reduce phantom reads from noisy images
.MinScanLines = 3
}
Dim scanFiles As String() = Directory.GetFiles("pos-scans/", "*.png")
For Each file As String In scanFiles
Dim results As BarcodeResults = BarcodeReader.Read(file, options)
If results.Count = 0 Then
' No barcode passed all validation layers
Console.Error.WriteLine($"REJECT {Path.GetFileName(file)}: " &
"no valid EAN-13/UPC barcode (checksum, confidence, or format mismatch)")
Continue For
End If
Dim primary As BarcodeResult = results.First()
' Post-read assertion: verify the decoded format matches expectations.
' ExpectBarcodeTypes already constrains the reader; this check documents
' intent and surfaces unexpected results during future changes.
If primary.BarcodeType <> BarcodeEncoding.EAN13 AndAlso
primary.BarcodeType <> BarcodeEncoding.UPCA AndAlso
primary.BarcodeType <> BarcodeEncoding.UPCE Then
Console.Error.WriteLine($"UNEXPECTED FORMAT {Path.GetFileName(file)}: " &
$"got {primary.BarcodeType}, expected EAN-13/UPC")
Continue For
End If
Console.WriteLine($"OK {Path.GetFileName(file)}: [{primary.BarcodeType}] {primary.Value}")
Next
What does the ConfidenceThreshold property do in IronBarcode?
The `ConfidenceThreshold` property in IronBarcode sets a quality gate for decoding, rejecting barcodes where the machine learning detector's confidence falls below a specified percentage.
How can IronBarcode combine checksum validation with format constraints?
IronBarcode combines checksum validation with format constraints using `BarcodeReaderOptions`. By setting properties like `ExpectBarcodeTypes`, `ConfidenceThreshold`, and `RemoveFalsePositive`, it creates a layered validation approach.