IronBarcodeでC#の読み取り速度を調整する方法

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronBarcodeは、読み取り速度の4つのオプション(Balancedを初期設定として推奨します。

はじめに

大量の BarCode セットを読み取る際には正確さが不可欠ですが、リソースの割り当てと処理効率も同様に重要な考慮事項です。 入力画像の品質によって、バーコードリーダーがどのように処理すべきかが決まります。鮮明な画像の場合は前処理を省略し、劣化したバーコードの場合はよりリソース集約的なオプションを使用して精度を向上させます。

IronBarcodeは処理速度と精度レベルを柔軟に選択できるため、バーコード読み取りプロセスのあらゆる側面を制御することができます。 入力イメージと利用可能なリソースに基づいて決定することができます。 より高度なバーコード読み取りシナリオについては、包括的なバーコード読み取りチュートリアルを参照してください。

この記事では、さまざまなシナリオに最適な読み取り速度を選択するためのガイドラインを提供します。 QRコードのサンプルを使用し、読み取り速度の変更が結果にどのように影響するかを実演します。 QRコードに特化して作業している場合は、C# QR Code Generator tutorial でテストサンプルを作成してください。

クイックスタート:バランスの取れた速度でBarCodeを読み取る

IronBarcodeの BarcodeReaderOptions を使用すると、スキャン時の Speed レベルを即座に設定できます。 この例では、Balanced設定を使用してBARCODEを迅速に読み取り、高速かつ信頼性の高い結果を得る方法を示しています。

  1. IronBarcode をNuGetパッケージマネージャでインストール

    PM > Install-Package BarCode
  2. このコード スニペットをコピーして実行します。

    var results = IronBarCode.BarcodeReader.Read("path/to/image.png", new IronBarCode.BarcodeReaderOptions { Speed = IronBarCode.ReadingSpeed.Balanced });
  3. 実際の環境でテストするためにデプロイする

    今日プロジェクトで IronBarcode を使い始めましょう無料トライアル

    arrow pointer


異なる読み取り速度のオプションは何ですか?

IronBarcodeは、ExtremeDetailの4つのオプションを提供しています。 ライブラリの機能を実証するために、劣化したBarCode画像と鮮明な画像を含むサンプルセットを使用して、各オプションを検証します。 サポートされているフォーマットの完全なリストについては、サポートされているバーコードフォーマットのページをご覧ください。

.NETベンチマークライブラリを使用して処理時間とメモリ使用量を測定し、各オプションの比較と各読み取り速度の理想的なシナリオを示します。 ベンチマークコードと、劣化したBarCodeの読み取り成功数をカウントする簡単な方法を実演します。 リーダーオプションの設定の詳細については、BarCodeリーダー設定例をご覧ください。

高速化オプションはいつ使用すべきですか?

Faster オプションは、最小限のリソースで最速の BARCODE 読み取りを実現しますが、精度は低下します。 このプロセスは画像の前処理を省略するため、入力画像がすでにシャープで鮮明な場合に最適です。

この例では、Speed プロパティを ReadingSpeed.Faster に設定し、BARCODEが格納されたディレクトリを読み込み、検出されたBARCODEを、その値、タイプ、および画像ごとの枚数とともにPRINTします。 さまざまな画像形式から BarCode を読み取る方法については、画像からバーコードを読み取るのガイドを参照してください。

:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-faster.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Faster
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"Faster could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
Imports IronBarCode
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Linq

Dim optionsFaster As New BarcodeReaderOptions With {
    .Speed = ReadingSpeed.Faster
}

' Directory containing PDF files
Dim folderPath As String = "YOUR_FILE_PATH"

' Get all PDF files in the directory
Dim pdfFiles = Directory.GetFiles(folderPath, "*.jpg")

Dim countFaster As Integer = 0
Dim stopwatch As Stopwatch = Stopwatch.StartNew()
For Each file In pdfFiles
    ' Read the barcode
    Dim results = BarcodeReader.Read(file, optionsFaster)

    If results.Any() Then
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}")
        For Each result In results
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}")
            countFaster += 1
        Next
    Else
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}")
    End If
Next

stopwatch.Stop()

' Print number of images the barcode reader could decode
Console.WriteLine($"Faster could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms")
$vbLabelText   $csharpLabel

Faster オプションは、430件中146件の BARCODE 結果を25秒で検出し、33.95%の精度を達成しました。 この方法は高速ですが、画像がきれいな状態でなければ適していません。 1つの画像で複数の BarCode を扱う場合は、reading multiple barcodes のガイドを参考にして、最適な設定を行ってください。

なぜBalancedが推奨される速度オプションなのか

Balanced オプションは、正確性と読みやすさのバランスを取っています。 IronBarcodeは、バーコード領域を明確にするために軽い画像処理を適用し、検出と読み取りを容易にします。 最近の画像では、軽い処理で正確な結果が得られることが多いため、この設定を推奨します。

同じ画像を使用して、Balancedが出力結果にどのような影響を与えるかを示しましょう。 非同期処理については、async and multithreading with IronBarcodeのガイドをご覧ください。

:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-balanced.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"Balanced could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
Imports IronBarCode
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Linq

Dim optionsFaster As New BarcodeReaderOptions With {
    .Speed = ReadingSpeed.Balanced
}

' Directory containing PDF files
Dim folderPath As String = "YOUR_FILE_PATH"

' Get all PDF files in the directory
Dim pdfFiles = Directory.GetFiles(folderPath, "*.jpg")

Dim countFaster As Integer = 0
Dim stopwatch As Stopwatch = Stopwatch.StartNew()
For Each file In pdfFiles
    ' Read the barcode
    Dim results = BarcodeReader.Read(file, optionsFaster)

    If results.Any() Then
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}")
        For Each result In results
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}")
            countFaster += 1
        Next
    Else
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}")
    End If
Next

stopwatch.Stop()

' Print number of images the barcode reader could decode
Console.WriteLine($"Balanced could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms")
$vbLabelText   $csharpLabel

Balanced オプションは、43秒間で430件中237件の BARCODE 結果を検出しました。 精度は55.11%で、Fasterに比べて大幅な改善が見られ、処理時間はわずかに増加したのみです。 このオプションは、メモリとスピードの効率的なバランスを維持するため、ほとんどの状況に最適で、出発点として推奨されます。 このバランスの取れたアプローチは、適切な画像前処理技術によって特に効果的に機能します。

詳細なスピードオプションはいつ必要ですか?

画像が著しくぼやけていたり歪んでいたりして、Detailedオプションを使用してください。 バーコード領域を明確にし、デジタルノイズを減らして検出を向上させるために、中程度の前処理を適用します。 ひどく劣化した画像については、画像補正ガイドを参照してください。このガイドでは、さまざまな前処理テクニックについて説明しています。

Detailed 設定を適用し、出力への影響を確認してみましょう。

:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-detailed.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Detailed
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"Detailed could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
Imports IronBarCode
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Linq

Dim optionsFaster As New BarcodeReaderOptions With {
    .Speed = ReadingSpeed.Detailed
}

' Directory containing PDF files
Dim folderPath As String = "YOUR_FILE_PATH"

' Get all PDF files in the directory
Dim pdfFiles = Directory.GetFiles(folderPath, "*.jpg")

Dim countFaster As Integer = 0
Dim stopwatch As Stopwatch = Stopwatch.StartNew()
For Each file In pdfFiles
    ' Read the barcode
    Dim results = BarcodeReader.Read(file, optionsFaster)

    If results.Any() Then
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}")
        For Each result In results
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}")
            countFaster += 1
        Next
    Else
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}")
    End If
Next

stopwatch.Stop()

' Print number of images the barcode reader could decode
Console.WriteLine($"Detailed could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms")
$vbLabelText   $csharpLabel

Detailed オプションは、5分30秒で430件中237件の BARCODE 結果を検出しました。 劣化の激しい BarCode での成功率は 55.11%で、その精度の高さを実証しています。 ただし、処理時間が大幅に増加するため、このオプションは劣化した BarCode 画像専用に使用する必要があります。 不完全な BarCode を扱う場合は、imperfect barcode handling example を参考にしてください。

どのような状況で極限まで詳細なスピードが要求されますか?

ExtremeDetail 設定は BARCODE 画像に対して重い処理を行うため、読み取り性能が大幅に低下します。 このCPU負荷の高いオプションは、1つの入力ファイル内で複数の不鮮明または不鮮明なBarCodeをスキャンする場合に最適です。他のオプションで望ましい結果が得られない場合の最後の手段として使用してください。 大量処理のシナリオでは、PDF ファイルから BarCode を読み取ります。PDF ファイルにはページごとに複数のバーコードが含まれていることがよくあります。

ExtremeDetail 設定を適用して、その影響を確認してみましょう。

:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-extreme-detailed.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.ExtremeDetail
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"ExtremeDetail could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
Imports IronBarCode
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Linq

Dim optionsFaster As New BarcodeReaderOptions With {
    .Speed = ReadingSpeed.ExtremeDetail
}

' Directory containing PDF files
Dim folderPath As String = "YOUR_FILE_PATH"

' Get all PDF files in the directory
Dim pdfFiles = Directory.GetFiles(folderPath, "*.jpg")

Dim countFaster As Integer = 0
Dim stopwatch As Stopwatch = Stopwatch.StartNew()

For Each file In pdfFiles
    ' Read the barcode
    Dim results = BarcodeReader.Read(file, optionsFaster)

    If results.Any() Then
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}")
        For Each result In results
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}")
            countFaster += 1
        Next
    Else
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}")
    End If
Next

stopwatch.Stop()

' Print number of images the barcode reader could decode
Console.WriteLine($"ExtremeDetail could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms")
$vbLabelText   $csharpLabel

ExtremeDetail オプションは、約10分で430枚の BARCODE 画像のうち313枚を識別しました。 著しく劣化したBarCodeに対して72.79%という驚異的な精度を達成していますが、リソースの消費量が多いため、最後の手段としてのみ適しています。 このオプションを使用する前に、画像の前処理を検討してください。

異なる速度はどのように比較されますか?

モード バーコードが見つかりました 平均時 ファイルあたりの時間 GC圧力 精度の向上
より速く 147/430 (33.95%) 25秒 0.058秒 高(第2世代:177K) ベースライン
バランスのとれた 237/430 (55.11%) 43秒 0.1秒 高(第2世代:151K) +62.32% 対 Faster
詳細 237/430 (55.11%) 5.50分 0.767秒 非常に高い (Gen2: 297K) +0% vs バランス
エクストリームディテール 313/430 (72.79%) 10.14分 1.414秒 エクストリーム(第2世代:474万) +32.08% 対 詳細

自分のアプリケーションに適した速度を選択するにはどうすればよいですか?

上記の比較に基づき、ExtremeDetailへと進め、出力結果の顕著な違いを特定してください。 ほとんどのケースでは、Balancedが適切に処理します。 Detailed および ExtremeDetail は、著しく歪んだ画像の場合にのみ使用してください。 鮮明でない、または品質の低い BARCODE については、速度設定と MinScanLines = 1 を組み合わせて、検出感度を高めてください。

Detailed および ExtremeDetail は中程度から高負荷の処理を実行しますが、単一のプロセスを使用するよりも、BARCODE読み取りの前に手動で画像フィルターを適用するなど、処理を分割した方が効率的な場合があります。 画像の前処理の詳細については、こちらのガイドを参照してください。

どの速度設定が私のユースケースにマッチしますか?

FasterからDetailed+ExtremeDetailのオプションまで、画質に基づくサンプリング速度選択のための決定木

よくある質問

利用可能な4つのバーコード読み取り速度のオプションは何ですか?

IronBarcodeは4つのReadingSpeedオプションを提供しています:Faster、Balanced、Detailed、ExtremeDetailです。各オプションは、処理速度と精度の異なるバランスを提供し、Balancedは、ほとんどのアプリケーションの出発点として推奨されています。

BarCode をスキャンする際の読み取り速度の設定方法を教えてください。

IronBarcodeのBarcodeReaderOptionsクラスを使って読み取り速度を設定することができます。新しいBarcodeReaderOptionsオブジェクトを作成し、Speedプロパティに希望のReadingSpeed値(Faster、Balanced、Detailed、ExtremeDetail)を設定し、Readメソッドに渡すだけです。

私のアプリケーションには、どの読解速度オプションを使用すればよいですか?

IronBarcodeは、ほとんどのアプリケーションでバランス速度設定から始めることをお勧めします。高品質で鮮明なバーコード画像がある場合は、Fasterモードを使用することができます。劣化した画像や品質の低い画像の場合は、精度を高めるためにDetailedまたはExtremeDetailモードの使用を検討してください。

読解速度の違いによるトレードオフとは?

IronBarcodeの読み取り速度は、処理速度と精度のトレードオフです。Fasterモードは画像を素早く処理しますが、画質の悪い画像ではバーコードを見逃す可能性があります。ExtremeDetailモードは最高の精度を提供しますが、より多くの処理時間とメモリリソースを必要とします。

異なる速度設定で複数のバーコード形式を読み取ることはできますか?

はい、IronBarcodeは全ての速度設定でQRコードを含む様々なバーコードフォーマットの読み取りをサポートしています。速度設定は処理方法に影響しますが、読み取れるバーコードの種類を制限するものではありません。完全なリストはサポートされているバーコードフォーマットのページをご覧ください。

画質はどのように読書速度に影響しますか?

画像の品質はIronBarcodeのスピード選択に直接影響します。鮮明で高品質なバーコード画像は、Fasterモードで効率的に処理できます。劣化した、ぼやけた、または低コントラストの画像は、正確なバーコード検出と読み取りを確実にするために、DetailedまたはExtremeDetailモードが必要です。

速度オプションを使用して BarCode を読み取るための最小限のワークフローを教えてください。

IronBarcodeの最小ワークフローは5つのステップで構成されています:1) C#ライブラリのダウンロード、2) BarCodeReaderOptionsを使用して読み取り速度を設定、3) 画像パスを使用してReadメソッドを呼び出し、4) バーコード値を抽出して印刷、5) 異なる速度間のパフォーマンストレードオフを評価。

読む速度の違いによるパフォーマンスへの影響を測定するにはどうすればよいですか?

IronBarcodeの異なる読み取り速度でのパフォーマンスは、.NETベンチマークライブラリを使用して測定し、処理時間とメモリ使用量を追跡することができます。これは、特定のユースケースとリソースの制約に最適な速度設定を特定するのに役立ちます。

カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 2,145,441 | バージョン: 2026.4 リリース
Still Scrolling Icon

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package BarCode
サンプルを実行する 文字列が BarCode になるのを見る。