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

창고랙.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에 나타납니다.
실패 경로

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

shipping-label.png (성공 경로 - 코드 128이 제약 조건과 일치함)

QR 형식 불일치.png (실패 경로 - 코드128 전용 필터에 의해 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입니다. 제한된 읽기는 필터가 예상하는 코드128을 즉시 감지하며, 광범위한 읽기는 모든 형식에서 동일한 결과를 확인시켜 줍니다.
실패 경로

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

pos-scan-1.png (성공)

pos-scan-2.png (성공)

pos-scan-3.png (성공)

warehouse-rack.png (실패 - 코드 128 거부됨)
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 필터는 유효한 모드10 체크섬을 가지고 있었고 신뢰도는 0.8 이상이었습니다.
실패 경로

1D 바코드가 유효하려면 필요한 최소 일치 스캔 라인의 수를 늘리려면 MinScanLines을 3으로 설정하십시오; 기본값은 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는 바코드 데이터의 체크섬을 계산하고 인코딩된 체크섬과 비교하여 스캐닝 중 데이터 무결성을 보장하며 암시적으로 체크섬 검증을 다룹니다.
BarcodeEncoding 필터란 무엇인가요?
IronBarcode의 BarcodeEncoding 필터는 스캐닝 중 읽거나 무시할 바코드 형식을 지정하게 하여 특정 바코드 유형에 집중함으로써 더 정확하고 효율적인 바코드 처리가 가능하도록 합니다.
IronBarcode는 결합 검증을 수행할 수 있나요?
네, IronBarcode는 스캐닝 도중 체크섬과 바코드 포맷을 모두 검토하여 올바르고 적절히 형식화된 바코드만 처리되도록 함으로써 결합된 검증을 수행할 수 있습니다.
C#에서 IronBarcode를 사용하여 바코드 읽기를 포맷으로 제한할 수 있나요?
네, IronBarcode는 포함하거나 제외할 형식을 지정하여 적용할 수 있으며, 이는 애플리케이션이 관련 있는 바코드 유형만 처리하게 합니다.
바코드 처리에서 포맷 인식 읽기가 중요한 이유는 무엇인가요?
포맷 인식 읽기가 중요합니다 왜냐하면 이를 통해 애플리케이션이 특정한 유형의 바코드만 처리하게 되므로, 속도와 정확도를 향상시키고 관련이 없거나 지원하지 않는 바코드 형식을 무시할 수 있습니다.
IronBarcode에서 포맷 인식 읽기를 어떻게 구현하나요?
IronBarcode에서 포맷 인식 읽기를 구현하려면 BarcodeEncoding 필터를 사용하여 읽고자 하는 바코드 형식을 지정합니다. 이는 라이브러리의 API를 통해서 가능하며, 바코드 스캔 요구 사항에 대해 정확한 제어가 가능합니다.
바코드 검증을 위해 IronBarcode를 사용하는 이점은 무엇인가요?
IronBarcode는 강력한 체크섬 검증, 포맷 인식 읽기, 넓은 범위의 바코드 표준 지원 등을 통해 바코드 처리에서 높은 정확성과 유연성을 제공합니다.
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.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.