C#에서 바코드 체크섬을 검증하고 형식 인식 읽기를 사용하는 방법
바코드 체크섬은 치환 오류를 감지하는 데 도움이 됩니다. 예를 들어, EAN-13 라벨에서 숫자 하나만 잘못 입력되어도 소포가 잘못된 창고로 배송될 수 있습니다. 형식 인식 읽기는 디코더를 예상되는 심볼로 제한함으로써 추가적인 유효성 검사 계층을 제공합니다. 이 접근 방식은 배경 노이즈으로 인한 오탐을 줄이고 불필요한 형식 감지기를 건너뛰어 스캔 시간을 단축합니다.
IronBarcode는 디코딩 중에 체크섬 검증을 자동으로 수행합니다. 각 심볼 체계의 검사 숫자 알고리즘은 기본적으로 실행되며, 검사에 실패한 바코드는 결과가 반환되기 전에 폐기됩니다. BarcodeReaderOptions.ExpectBarcodeTypes 속성은 읽기를 특정 형식으로 제한하고, RemoveFalsePositive는 판독 결과가 불확실한 경우 2차 스캔을 추가합니다.
이 가이드는 바코드 체크섬을 검증하고 예상되는 형식으로 읽기를 제한하는 방법을 설명하며 BarcodeReaderOptions를 사용하여 두 가지 기술을 계층화하여 품질 관문으로 결합합니다.
BarcodeReaderOptions를 ExpectBarcodeTypes 및 RemoveFalsePositive로 구성하여 자동 체크섬 검증을 통해 예상되는 심볼로지로 읽기를 제한합니다.
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);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)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)최소 워크플로우(5단계)
- NuGet에서 IronBarcode 라이브러리 다운로드
BarcodeReaderOptions인스턴스 생성ExpectBarcodeTypes를 파이프라인에 존재하는 심볼로지로 설정RemoveFalsePositive를 활성화하여 2차 검증 수행- 바코드를 디코딩하려면
BarcodeReader.Read를 호출하세요. 디코딩 중에 체크섬이 자동으로 검증됩니다.
바코드 체크섬을 검증하는 방법은 무엇인가요?
IronBarcode는 각 심볼로지 규격에 따라 디코딩 중에 체크섬을 검증합니다. 예를 들어, EAN-13 바코드를 읽을 때 Mod10 검사 숫자는 처음 12자리 숫자를 사용하여 계산한 다음 13번째 자리 숫자와 비교합니다. 숫자가 일치하지 않으면, 바코드는 조용히 거부되어 BarcodeResults 컬렉션에 나타나지 않습니다. 이 접근 방식은 UPC-A, UPC-E, EAN-8, Code128, ITF 등을 포함하여 필수 검사 숫자가 있는 모든 형식에 적용됩니다.
이 내재된 모델은 명시적 토글을 노출하는 라이브러리와 다릅니다. 아래 표는 두 가지 접근 방식을 비교합니다:
| 측면 | IronBarcode | Aspose.BarCode |
|---|---|---|
| 검증 트리거 | 자동 실행; 모든 디코딩 과정에서 실행됩니다. | 명시적 설정: ChecksumValidation.On 켜기/ Off / Default |
| 개발자 작업 필요 | 해당 사항 없음; 유효하지 않은 바코드는 결과에서 제외됩니다. | 읽기 전에 BarcodeSettings.ChecksumValidation 설정하세요. |
| 체크섬 비활성화 | 노출되지 않음; 필수 형식의 경우 체크섬이 항상 적용됩니다. | 예, ChecksumValidation.Off 검증을 건너뛰도록 설정합니다. |
| 선택적 체크섬 형식 (코드39) | Confidence 와 RemoveFalsePositive 사용하여 품질이 낮은 리드를 필터링합니다. | EnableChecksum.Yes 사용하여 명시적으로 활성화합니다. |
| 실패 동작 | 바코드가 결과에서 조용히 생략됨 | 바코드에는 수동 검사를 위한 별도의 체크섬 값이 표시될 수 있습니다. |
Code39과 같은 선택적 체크섬을 가진 심볼로지의 경우, 라이브러리는 체크섬 전환 대신 신뢰도 점수와 RemoveFalsePositive를 사용합니다.
입력
Code128 창고 랙 라벨(성공 경로)과 바코드가 없는 빈 이미지(실패 경로).

warehouse-rack.png (성공 경로)

blank-no-barcode.png (실패 경로 - 바코드 없음)
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");
}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 IfImports 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출력
성공 경로

창고 랙 바코드가 페이지 0에서 RACK-A1-LOT-7382으로 나왔습니다. 85% 신뢰도 임계값을 통과하고 체크섬 검증을 통과했기 때문에 BarcodeResults에 표시됩니다.
실패 경로

ConfidenceThreshold를 기본값인 0.7보다 높이면 Code39와 같은 선택적 체크섬 심볼로지에 대한 이 관문을 더욱 강화할 수 있습니다.
체크섬 유효성 검사가 완료되었으므로 다음 단계는 파이프라인에서 요구하는 바코드 형식만 판독할 수 있도록 제한하는 것입니다.
형식 인식 바코드 읽기 사용 방법은 무엇인가요?
BarcodeEncoding 열거형은 플래그 유형으로, 이를 통해 다양한 형식을 비트 OR 연산자를 사용하여 결합할 수 있습니다. ExpectBarcodeTypes를 설정하면 리더가 해당 형식으로 제한되며 다른 형식의 감지를 건너뜁니다.
| 값 | 범주 | 설명 | 체크섬 |
|---|---|---|---|
BarcodeEncoding.All | 메타 | 지원되는 모든 형식(기본 동작) | 개별 형식 |
BarcodeEncoding.AllOneDimensional | 메타 | 적층형을 포함한 모든 선형 (1D) 형식 | 개별 형식 |
BarcodeEncoding.AllTwoDimensional | 메타 | 모든 매트릭스/그리드 (2D) 형식 | 개별 형식 |
BarcodeEncoding.Code128 | 1D | 고밀도 영숫자(물류, 배송) | 필수 (가중 Mod103) |
BarcodeEncoding.EAN13 | 1D | 소매 제품 식별 번호(13자리) | 필수 (Mod10) |
BarcodeEncoding.QRCode | 2D | 대용량 매트릭스(URL, 구조화된 데이터) | 리드-솔로몬 ECC |
BarcodeEncoding.Code39 | 1D | 영숫자 (방위, 자동차) | 선택적 (Mod43) |
BarcodeEncoding.UPCA | 1D | 북미 소매업 (12자리 숫자) | 필수 (Mod10) |
BarcodeEncoding.DataMatrix | 2D | 컴팩트 매트릭스(전자, 제약) | 리드-솔로몬 ECC |
BarcodeEncoding.PDF417 | 2D | 적층형 (신분증, 운송) | 리드-솔로몬 ECC |
속도 외에도, 형식 세트를 제한하는 것은 유효성 검사 관문 역할을 합니다. 목록에 없는 심볼의 바코드는 이미지에 물리적으로 존재하더라도 결과에서 제외됩니다.
입력
Code128 배송 라벨(성공 경로)과 Code128 전용 제약 조건과 일치하지 않는 QR 코드(실패 경로).

shipping-label.png (성공 경로 - Code128 일치)

qr-format-mismatch.png (실패 경로 - Code128 전용 필터에 의해 QR 거부됨)
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}");
}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}")
NextImports 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출력
성공 경로

배송 라벨의 값은 SHIP-2024-00438입니다. 제한된 읽기는 필터가 예상하는 Code128을 즉시 감지하며, 광범위한 읽기는 모든 형식에서 동일한 결과를 확인시켜 줍니다.
실패 경로

제한된 읽기에서 결과가 비어 있는 것은 오류가 아니라 유효성 검사 신호입니다. 차이점을 기록하여 검토하도록 하십시오.
바코드 유형이 혼합된 파이프라인(예: EAN-13 제품 코드와 Code128 추적 번호가 모두 포함된 포장 명세서)의 경우 예상되는 형식을 결합하십시오.
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
};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
}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
}각 반환된 BarcodeResult.BarcodeType는 어떤 형식이 디코딩되었는지 식별하여 다운스트림 라우팅을 가능하게 합니다.
어떤 심볼로지가 체크섬 검증을 지원합니까?
모든 바코드 형식이 체크섬을 동일한 방식으로 사용하지는 않습니다. 다음 표는 일반적인 심볼로지를 오류 검출 특성에 매핑하여 각 형식에 대해 ConfidenceThreshold 및 RemoveFalsePositive를 얼마나 공격적으로 설정할지에 대한 정보를 제공합니다:
| 심볼로지 | 체크섬 유형 | 필수인가요? | 추천 |
|---|---|---|---|
| EAN-13 / EAN-8 | Mod10 | 예 | 기본 설정으로 충분합니다. 체크섬은 항상 적용됩니다. |
| UPC-A / UPC-E | Mod10 | 예 | 기본 설정으로 충분합니다. 쓰기 시 검사 숫자가 자동으로 수정됩니다. |
| Code128 | 가중 Mod103 | 예 | 기본 설정으로 충분하며, 사양에 따라 필수 사항입니다. |
| Code39 | Mod43 | 선택 사항 | ConfidenceThreshold를 0.8 이상으로 올리고 RemoveFalsePositive를 활성화하세요 |
| Codabar | Mod16 | 선택 사항 | Code39와 동일하게 신뢰도를 품질 검증 기준으로 사용합니다. |
| ITF | Mod10 | 선택 사항 | 인터리브 형식에 대해 RemoveFalsePositive 활성화 |
| QRCode / DataMatrix | 리드-솔로몬 ECC | 언제나 | 구조적 오류 수정; 추가 설정 불필요 |
| PDF417 | 리드-솔로몬 ECC | 언제나 | QR/DataMatrix와 마찬가지로 오류 수정 기능이 내장되어 있습니다. |
QR, DataMatrix, PDF417과 같은 2D 심볼의 경우 오류 수정 기능이 인코딩 구조에 통합되어 있습니다. 이러한 형식은 간단한 검사 숫자에 의존하지 않고도 부분적인 손상으로부터 복구할 수 있습니다. ML 감지 단계 동안 ConfidenceThreshold가 여전히 적용되며, 디코드 단계는 심볼로지의 내장 중복성으로부터 이점을 얻습니다.
이제 두 가지 기법을 모두 이해했으니, 이들을 결합하여 실제 운영 환경에서 바로 사용할 수 있는 검증 패턴을 만들어 보겠습니다.
체크섬을 형식 제약과 결합하는 방법은?
운영 환경에 사용할 검증 패턴은 ExpectBarcodeTypes, RemoveFalsePositive, ConfidenceThreshold 및 Speed를 단일 BarcodeReaderOptions 객체에 설정합니다. 이들은 함께 계층형 게이트를 형성합니다. 형식 제약 조건은 검색 공간을 좁히고, 체크섬 유효성 검사는 데이터 무결성을 보장하며, 신뢰도 임계값 설정은 불완전한 디코딩을 필터링하고, 오탐 제거는 2차 검증 단계를 추가합니다.
입력
pos-scans/ 디렉터리에서 세 개의 POS 스캔 바코드가 성공 경로로 사용되었습니다: 두 개의 EAN-13과 하나의 UPC-A. Code128 창고 랙 라벨이 실패 경로로 사용됩니다 - EAN-13/UPC-A 제약이 이를 거부하고 REJECT 줄을 기록합니다.

pos-scan-1.png (성공)

pos-scan-2.png (성공)

pos-scan-3.png (성공)

warehouse-rack.png (실패 - Code128 거부됨)
using IronBarCode;
using System;
using System.IO;
using System.Linq;
// 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}");
}using IronBarCode;
using System;
using System.IO;
using System.Linq;
// 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}");
}Imports IronBarCode
Imports System
Imports System.IO
Imports System.Linq
' 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 {
.ExpectBarcodeTypes = BarcodeEncoding.EAN13 Or BarcodeEncoding.UPCA Or BarcodeEncoding.UPCE,
.ConfidenceThreshold = 0.8,
.RemoveFalsePositive = True,
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = False,
.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
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()
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}")
NextImports IronBarCode
Imports System
Imports System.IO
Imports System.Linq
' 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 {
.ExpectBarcodeTypes = BarcodeEncoding.EAN13 Or BarcodeEncoding.UPCA Or BarcodeEncoding.UPCE,
.ConfidenceThreshold = 0.8,
.RemoveFalsePositive = True,
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = False,
.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
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()
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출력
성공 경로

POS 스캔 이미지 세 장 모두 검증을 통과했습니다. 리더는 5901234123471, 4006381333931, 및 012345678905 값을 반환했습니다. 각 항목이 EAN13 | UPCA | UPCE 필터와 일치했고, 유효한 Mod10 체크섬을 가지며 신뢰도가 0.8보다 높습니다.
실패 경로

MinScanLines를 3으로 설정하면 1D 바코드가 유효하기 위해 필요한 일치하는 스캔 라인의 최소 수가 증가합니다; 기본값은 2입니다. 이 값을 높이면 노이즈가 있는 스캔 라인으로 인한 잘못된 판독 위험이 줄어들지만, 얇거나 부분적으로 손상된 바코드를 놓칠 수 있습니다. 깨끗하게 인쇄된 라벨이 있는 소매 POS 환경에서는 3이라는 값이 처리량에 영향을 주지 않으면서 유효성 검사를 강화하는 보수적인 선택입니다.
읽기 후 BarcodeType을 확인하는 어설션은 심층 방어 수단입니다: ExpectBarcodeTypes가 이미 필터링하지만, 명시적인 검사는 의도를 문서화하고 런타임 비용 없이 구성 드리프트를 포착합니다. 속도 조정을 위해, ReadingSpeed.Faster은 깔끔하게 인쇄된 라벨에 적합합니다; Detailed 및 ExtremeDetail는 긴 스캔 시간을 대가로 손상되거나 조명이 약한 바코드를 복구합니다.
다음 단계는 무엇입니까?
이 기사에서는 IronBarcode의 내재적 체크섬 검증 모델, 형식 제한된 읽기를 위한 BarcodeEncoding 플래그 열거형 및 ExpectBarcodeTypes, ConfidenceThreshold, RemoveFalsePositive 및 MinScanLines를 계층화된 품질 관문으로 사용하는 결합된 검증 패턴을 다루었습니다.
추가 읽기를 위해 이 리소스를 탐색하세요:
- IronBarcode 튜토리얼 - 바코드 읽기는 엔드 투 엔드 읽기 안내서입니다.
- 오탐 방지는
RemoveFalsePositive메커니즘에 대한 자세한 내용을 제공합니다. - 신뢰도 임계값 예제는 ML 기반 감지 조정을 위한 것입니다.
- 출력 데이터 형식은
BarcodeResult속성 참조입니다. - 이미지 교정 방법은 디코드 정확성을 향상시키는 필터입니다.
- BarcodeReaderOptions API 레퍼런스는 완전한 구성 설명서를 제공합니다.
- BarcodeEncoding API 레퍼런스는 지원되는 모든 심볼로지를 나열합니다.
무료 체험 라이선스 받기는 라이브 환경에서 모든 기능을 테스트할 수 있으며, 라이선스 옵션 보기는 파이프라인이 프로덕션 준비가 되었을 때 사용할 수 있습니다.
자주 묻는 질문
바코드 체크섬을 검증하는 목적은 무엇입니까?
바코드 체크섬을 검증하면 바코드 스캐닝 중 데이터 손상이 발생하지 않도록 보장합니다. IronBarcode는 각 심볼로지의 체크 디지트 알고리즘에 대한 체크섬 검증을 자동으로 수행합니다.
IronBarcode는 형식 인식 읽기를 어떻게 처리합니까?
IronBarcode는 BarcodeReaderOptions.ExpectBarcodeTypes 속성을 사용하여 특정 바코드 심볼로지로 읽기를 제한합니다. 이는 잘못된 긍정을 줄이고 형식 감지기를 예상되는 유형으로만 제한하여 스캐닝 효율성을 향상합니다.
IronBarcode가 자동 체크섬 검증을 수행할 수 있습니까?
예, IronBarcode는 디코딩 과정에서 자동 체크섬 검증을 수행합니다. 이 검증에 실패한 바코드는 결과가 반환되기 전에 폐기됩니다.
IronBarcode에서 `RemoveFalsePositive` 기능의 용도는 무엇입니까?
RemoveFalsePositive 기능은 IronBarcode에서 모호한 읽기를 제거하여 바코드 검출의 정확성을 높이는 보조 스캔 검증을 추가합니다.
어떤 심볼로지가 IronBarcode에서 필수 체크섬 검증을 지원합니까?
EAN-13, UPC-A, Code128 등의 심볼로지가 필수 체크섬 검증을 지원합니다. IronBarcode는 이러한 형식에 대한 체크섬 검사를 자동으로 실행합니다.
IronBarcode로 바코드 읽기 형식에 제약을 어떻게 설정할 수 있습니까?
ExpectBarcodeTypes 속성을 사용하여 IronBarcode에서 바코드 읽기 형식에 제약을 설정할 수 있습니다. 이는 IronBarcode가 디코드해야 하는 바코드 유형을 지정하고 제한할 수 있게 합니다.
바코드 읽기에서 형식 제약을 사용하는 이점은 무엇입니까?
형식 제약은 특정 심볼로지로 검색을 제한함으로써 불필요한 잡음을 피하고 스캐닝 속도를 향상하여 스캐닝 오류를 줄이는 데 도움을 줍니다.
IronBarcode는 Code39와 같은 선택적 체크섬 형식의 바코드를 어떻게 처리합니까?
Code39와 같은 선택적 체크섬 형식의 경우, IronBarcode는 신뢰성 점수 및 RemoveFalsePositive 기능을 조합하여 저품질 읽기를 걸러냅니다.
IronBarcode에서 ConfidenceThreshold 속성은 무엇을 하나요?
ConfidenceThreshold 속성은 IronBarcode에서 디코딩을 위한 품질 게이트를 설정하여 머신러닝 감지기의 신뢰성이 지정된 백분율 이하로 떨어진 바코드를 거부합니다.
IronBarcode는 체크섬 검증과 형식 제약을 어떻게 결합할 수 있습니까?
IronBarcode는 BarcodeReaderOptions를 사용하여 체크섬 검증과 형식 제약을 결합합니다. ExpectBarcodeTypes, ConfidenceThreshold, RemoveFalsePositive와 같은 속성을 설정하여 중첩된 검증 접근 방식을 만듭니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.