フッターコンテンツにスキップ
IRONOCRの使い方

レシートスキャンAPI: C#とIronOCRを使用してレシートからデータを抽出する

レシートスキャンAPIは、OCR技術を使用してレシートからのデータ抽出を自動化し、手入力によるエラーを大幅に削減し、処理速度を向上させます。 このガイドでは、 IronOCRをC#で使用して、レシート画像からベンダー名、日付、商品、価格、合計金額を正確に抽出する方法を示します。画像の前処理機能が組み込まれており、複数のフォーマットにも対応しています。

レシートのスキャンにIronOCRを選ぶ理由とは?

IronOCRは、スキャンした文書、画像、PDFから信頼性の高いテキスト抽出を提供する、柔軟性の高いOCRライブラリです。 IronOCRは、高度なアルゴリズム、コンピュータビジョン、機械学習モデルを活用することで、困難な状況下でも高い精度を保証します。 このライブラリは複数の言語とフォントスタイルをサポートしているため、グローバルなアプリケーションに適しています。 IronOCRをアプリケーションに組み込むことで、データ入力とテキスト分析を自動化し、生産性を向上させることができます。

IronOCRはどのようにしてレシート画像からテキストを抽出するのですか?

IronOCRは、文書、写真、スクリーンショット、ライブカメラ映像からテキストを抽出し、JSON形式のレスポンスとして出力します。 IronOCRは、高度なアルゴリズムと機械学習を用いて画像データを分析し、文字を認識して、機械が読み取り可能なテキストに変換します。 このライブラリは、独自の改良を加えたTesseract 5テクノロジーを採用しており、優れた精度を実現しています。

IronOCRが領収書処理に優れている理由とは?

IronOCRは、低品質のスキャン画像、さまざまなレシート形式、および異なる向きの処理に優れています。 内蔵の画像前処理フィルターが処理前に自動的に画質を向上させるため、しわくちゃになったり色あせたりしたレシートでも最適な結果が得られます。

IronOCRを使用するには何が必要ですか?

IronOCRを使用する前に、以下の前提条件が満たされていることを確認してください。

どのような開発環境がサポートされていますか?

1.開発環境:Visual Studioなどの適切なIDEをインストールしてください。 IronOCRは、 WindowsLinuxmacOSAzure 、およびAWSをサポートしています。

必要なプログラミングスキルは何ですか?

  1. C#の知識:基本的なC#の理解は、コード例を修正するのに役立ちます。 IronOCRは、簡単なサンプルAPIドキュメントを提供します。

どのソフトウェア依存関係が必要ですか?

  1. IronOCR のインストール: NuGetパッケージ マネージャーを使用してインストールします。 プラットフォーム固有の依存関係が必要になる場合があります。

ライセンスキーは必要ですか?

4.ライセンスキー(オプション) :無料トライアルあり。 実運用にはライセンスが必要です。

レシートスキャン用の新しいVisual Studioプロジェクトを作成するにはどうすればよいですか?

Visual Studioで新しいプロジェクトを開始するにはどうすればよいですか?

Visual Studio を開いて [ファイル] に移動し、[新規] にマウスを移動して [プロジェクト] をクリックします。

Visual Studio IDE のファイル メニューが展開され、 新しいプロジェクト画像

どのプロジェクトテンプレートを選択すべきですか?

"コンソールアプリケーション"を選択し、"次へ"をクリックします。 このテンプレートは、Webアプリケーションに実装する前にIronOCRを学習するのに最適です。

Visual Studio の コンソールアプリケーション

レシートスキャナープロジェクトにどんな名前を付けたらいいでしょうか?

プロジェクト名と場所を入力し、"次へ"をクリックしてください。 "ReceiptScannerAPI"のような分かりやすい名前を選んでください。

Visual Studio で C# が選択され、ソリューション設定が表示された プロジェクト設定

どの.NET Frameworkバージョンを選択すべきですか?

最適な互換性を確保するには、 .NET 5.0以降を選択し、"作成"をクリックしてください。

Visual Studio の ターゲットフレームワーク

プロジェクトにIronOCRをインストールするにはどうすればよいですか?

インストール方法は2種類あります。

NuGetパッケージマネージャー方式はどのように使用すればよいですか?

ツール> NuGetパッケージ マネージャー>ソリューションのNuGetパッケージの管理に移動します。

Visual Studio NuGetパッケージ マネージャーの設定ダイアログ(パッケージ ソース構成付き)、ソリューション エクスプローラー内の C# プロジェクト構造 NuGetパッケージマネージャー

IronOCRを検索してパッケージをインストールしてください。 英語以外のレシートについては、言語固有のパッケージをインストールしてください。

 Visual Studio のNuGetパッケージ マネージャーで、メイン ライブラリとアラビア語、ヘブライ語、スペイン語の言語固有の OCR パッケージを含むインストール済みのIronOCRパッケージを表示しています。 IronOCR

コマンドラインインストールはどのように行うのですか?

  1. [ツール] > [NuGetパッケージ マネージャー] > [パッケージ マネージャー コンソール]に移動します。
  2. 次のコマンドを入力してください。

    Install-Package IronOcr

     related to コマンドラインインストールはどのように行うのですか? パッケージマネージャーコンソール

IronOCRを使ってレシートデータを素早く抽出するにはどうすればよいですか?

わずか数行のコードでレシートデータを抽出できます。

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

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

    using IronOcr;
    using System;
    
    var ocr = new IronTesseract();
    
    // Configure for receipt scanning
    ocr.Configuration.ReadBarCodes = true;
    ocr.Configuration.WhiteListCharacters = "0123456789.$,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz% ";
    
    using (var input = new OcrInput(@"receipt.jpg"))
    {
        // Apply automatic image enhancement
        input.DeNoise();
        input.Deskew();
        input.EnhanceResolution(225);
    
        // Extract text from receipt
        var result = ocr.Read(input);
    
        // Display extracted text and confidence
        Console.WriteLine($"Extracted Text:\n{result.Text}");
        Console.WriteLine($"\nConfidence: {result.Confidence}%");
    }
  3. 実際の環境でテストするためにデプロイする

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

    arrow pointer

レシート画像から構造化データを抽出するにはどうすればよいですか?

IronOCRは、様々な種類の文書から明細項目、価格、税金、合計金額を抽出します。このライブラリは、 PDF複数ページのTIFFファイル、および様々な画像フォーマットに対応しています。

using IronOcr;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class ReceiptScanner
{
    static void Main()
    {
        var ocr = new IronTesseract();

        // Configure OCR for optimal receipt reading
        ocr.Configuration.WhiteListCharacters = "0123456789.$,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz% ";
        ocr.Configuration.BlackListCharacters = "~`@#*_}{][|\\";
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;

        // Load the image of the receipt
        using (var input = new OcrInput(@"r2.png"))
        {
            // Apply image enhancement filters
            input.Deskew(); // Fix image rotation
            input.EnhanceResolution(225); // Optimal DPI for receipts
            input.DeNoise(); // Remove background noise
            input.Sharpen(); // Improve text clarity

            // Perform OCR on the input image
            var result = ocr.Read(input);

            // Regular expression patterns to extract relevant details from the OCR result
            var descriptionPattern = @"\w+\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)";
            var pricePattern = @"\$\d+(\.\d{2})?";
            var datePattern = @"\d{1,2}[/-]\d{1,2}[/-]\d{2,4}";

            // Variables to store extracted data
            var descriptions = new List<string>();
            var unitPrices = new List<decimal>();
            var taxes = new List<decimal>();
            var amounts = new List<decimal>();

            var lines = result.Text.Split('\n');
            foreach (var line in lines)
            {
                // Match each line against the description pattern
                var descriptionMatch = Regex.Match(line, descriptionPattern);
                if (descriptionMatch.Success)
                {
                    descriptions.Add(descriptionMatch.Groups[1].Value.Trim());
                    unitPrices.Add(decimal.Parse(descriptionMatch.Groups[2].Value));

                    // Calculate tax and total amount for each item
                    var tax = unitPrices[unitPrices.Count - 1] * 0.15m;
                    taxes.Add(tax);
                    amounts.Add(unitPrices[unitPrices.Count - 1] + tax);
                }

                // Extract date if found
                var dateMatch = Regex.Match(line, datePattern);
                if (dateMatch.Success)
                {
                    Console.WriteLine($"Receipt Date: {dateMatch.Value}");
                }
            }

            // Output the extracted data
            for (int i = 0; i < descriptions.Count; i++)
            {
                Console.WriteLine($"Description: {descriptions[i]}");
                Console.WriteLine($"Quantity: 1.00 Units");
                Console.WriteLine($"Unit Price: ${unitPrices[i]:0.00}");
                Console.WriteLine($"Taxes: ${taxes[i]:0.00}");
                Console.WriteLine($"Amount: ${amounts[i]:0.00}");
                Console.WriteLine("-----------------------");
            }

            // Calculate and display totals
            var subtotal = unitPrices.Sum();
            var totalTax = taxes.Sum();
            var grandTotal = amounts.Sum();

            Console.WriteLine($"\nSubtotal: ${subtotal:0.00}");
            Console.WriteLine($"Total Tax: ${totalTax:0.00}");
            Console.WriteLine($"Grand Total: ${grandTotal:0.00}");
        }
    }
}
using IronOcr;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class ReceiptScanner
{
    static void Main()
    {
        var ocr = new IronTesseract();

        // Configure OCR for optimal receipt reading
        ocr.Configuration.WhiteListCharacters = "0123456789.$,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz% ";
        ocr.Configuration.BlackListCharacters = "~`@#*_}{][|\\";
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;

        // Load the image of the receipt
        using (var input = new OcrInput(@"r2.png"))
        {
            // Apply image enhancement filters
            input.Deskew(); // Fix image rotation
            input.EnhanceResolution(225); // Optimal DPI for receipts
            input.DeNoise(); // Remove background noise
            input.Sharpen(); // Improve text clarity

            // Perform OCR on the input image
            var result = ocr.Read(input);

            // Regular expression patterns to extract relevant details from the OCR result
            var descriptionPattern = @"\w+\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)";
            var pricePattern = @"\$\d+(\.\d{2})?";
            var datePattern = @"\d{1,2}[/-]\d{1,2}[/-]\d{2,4}";

            // Variables to store extracted data
            var descriptions = new List<string>();
            var unitPrices = new List<decimal>();
            var taxes = new List<decimal>();
            var amounts = new List<decimal>();

            var lines = result.Text.Split('\n');
            foreach (var line in lines)
            {
                // Match each line against the description pattern
                var descriptionMatch = Regex.Match(line, descriptionPattern);
                if (descriptionMatch.Success)
                {
                    descriptions.Add(descriptionMatch.Groups[1].Value.Trim());
                    unitPrices.Add(decimal.Parse(descriptionMatch.Groups[2].Value));

                    // Calculate tax and total amount for each item
                    var tax = unitPrices[unitPrices.Count - 1] * 0.15m;
                    taxes.Add(tax);
                    amounts.Add(unitPrices[unitPrices.Count - 1] + tax);
                }

                // Extract date if found
                var dateMatch = Regex.Match(line, datePattern);
                if (dateMatch.Success)
                {
                    Console.WriteLine($"Receipt Date: {dateMatch.Value}");
                }
            }

            // Output the extracted data
            for (int i = 0; i < descriptions.Count; i++)
            {
                Console.WriteLine($"Description: {descriptions[i]}");
                Console.WriteLine($"Quantity: 1.00 Units");
                Console.WriteLine($"Unit Price: ${unitPrices[i]:0.00}");
                Console.WriteLine($"Taxes: ${taxes[i]:0.00}");
                Console.WriteLine($"Amount: ${amounts[i]:0.00}");
                Console.WriteLine("-----------------------");
            }

            // Calculate and display totals
            var subtotal = unitPrices.Sum();
            var totalTax = taxes.Sum();
            var grandTotal = amounts.Sum();

            Console.WriteLine($"\nSubtotal: ${subtotal:0.00}");
            Console.WriteLine($"Total Tax: ${totalTax:0.00}");
            Console.WriteLine($"Grand Total: ${grandTotal:0.00}");
        }
    }
}
$vbLabelText   $csharpLabel

レシートのスキャン精度を向上させるには、どのような技術が有効ですか?

正確なレシートスキャンを実現するための重要なテクニック: -文字ホワイトリスト:認識対象を想定される文字に限定します -画像前処理傾き補正解像度向上、ノイズ除去を使用 -パターンマッチング:正規表現を使用して構造化データを抽出します -信頼度スコアリング認識の信頼度に基づいて結果を検証します

Visual Studio デバッグ コンソールに PDF から抽出した請求書データが表示され、説明、数量、価格、税金、合計を含む項目が表示されます 出力

レシートの内容全体を抽出するにはどうすればよいですか?

書式を保持したまま、領収書の全内容を抽出します。

using IronOcr;
using System;
using System.Linq;

class WholeReceiptExtractor
{
    static void Main()
    {
        var ocr = new IronTesseract();

        // Configure for receipt scanning
        ocr.Configuration.ReadBarCodes = true; // Enable barcode detection
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5; // Use latest engine
        ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Best accuracy

        using (var input = new OcrInput(@"r3.png"))
        {
            // Apply automatic image correction
            input.WithTitle("Receipt Scan");

            // Use computer vision to find text regions
            var textRegions = input.FindTextRegions();
            Console.WriteLine($"Found {textRegions.Count()} text regions");

            // Apply optimal filters for receipt processing
            input.ApplyOcrInputFilters();

            // Perform OCR on the entire receipt
            var result = ocr.Read(input);

            // Display extracted text
            Console.WriteLine("=== EXTRACTED RECEIPT TEXT ===");
            Console.WriteLine(result.Text);

            // Get detailed results
            Console.WriteLine($"\n=== OCR STATISTICS ===");
            Console.WriteLine($"OCR Confidence: {result.Confidence:F2}%");
            Console.WriteLine($"Pages Processed: {result.Pages.Length}");
            Console.WriteLine($"Paragraphs Found: {result.Paragraphs.Length}");
            Console.WriteLine($"Lines Detected: {result.Lines.Length}");
            Console.WriteLine($"Words Recognized: {result.Words.Length}");

            // Extract any barcodes found
            if (result.Barcodes.Any())
            {
                Console.WriteLine("\n=== BARCODES DETECTED ===");
                foreach(var barcode in result.Barcodes)
                {
                    Console.WriteLine($"Type: {barcode.Type}");
                    Console.WriteLine($"Value: {barcode.Value}");
                    Console.WriteLine($"Location: X={barcode.X}, Y={barcode.Y}");
                }
            }

            // Save as searchable PDF
            result.SaveAsSearchablePdf("receipt_searchable.pdf");
            Console.WriteLine("\nSearchable PDF saved as: receipt_searchable.pdf");

            // Export as hOCR for preservation
            result.SaveAsHocrFile("receipt_hocr.html");
            Console.WriteLine("hOCR file saved as: receipt_hocr.html");
        }
    }
}
using IronOcr;
using System;
using System.Linq;

class WholeReceiptExtractor
{
    static void Main()
    {
        var ocr = new IronTesseract();

        // Configure for receipt scanning
        ocr.Configuration.ReadBarCodes = true; // Enable barcode detection
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5; // Use latest engine
        ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Best accuracy

        using (var input = new OcrInput(@"r3.png"))
        {
            // Apply automatic image correction
            input.WithTitle("Receipt Scan");

            // Use computer vision to find text regions
            var textRegions = input.FindTextRegions();
            Console.WriteLine($"Found {textRegions.Count()} text regions");

            // Apply optimal filters for receipt processing
            input.ApplyOcrInputFilters();

            // Perform OCR on the entire receipt
            var result = ocr.Read(input);

            // Display extracted text
            Console.WriteLine("=== EXTRACTED RECEIPT TEXT ===");
            Console.WriteLine(result.Text);

            // Get detailed results
            Console.WriteLine($"\n=== OCR STATISTICS ===");
            Console.WriteLine($"OCR Confidence: {result.Confidence:F2}%");
            Console.WriteLine($"Pages Processed: {result.Pages.Length}");
            Console.WriteLine($"Paragraphs Found: {result.Paragraphs.Length}");
            Console.WriteLine($"Lines Detected: {result.Lines.Length}");
            Console.WriteLine($"Words Recognized: {result.Words.Length}");

            // Extract any barcodes found
            if (result.Barcodes.Any())
            {
                Console.WriteLine("\n=== BARCODES DETECTED ===");
                foreach(var barcode in result.Barcodes)
                {
                    Console.WriteLine($"Type: {barcode.Type}");
                    Console.WriteLine($"Value: {barcode.Value}");
                    Console.WriteLine($"Location: X={barcode.X}, Y={barcode.Y}");
                }
            }

            // Save as searchable PDF
            result.SaveAsSearchablePdf("receipt_searchable.pdf");
            Console.WriteLine("\nSearchable PDF saved as: receipt_searchable.pdf");

            // Export as hOCR for preservation
            result.SaveAsHocrFile("receipt_hocr.html");
            Console.WriteLine("hOCR file saved as: receipt_hocr.html");
        }
    }
}
$vbLabelText   $csharpLabel

Visual Studio デバッグ コンソールに PDF から抽出した請求書データが表示され、説明、数量、価格、税金、合計を含む項目が表示されます 領収書スキャンAPI出力

レシートのスキャン性能を向上させる高度な機能とは?

IronOCRは、レシートのスキャン精度を大幅に向上させる高度な機能を複数提供しています。

IronOCRはどの言語をサポートしていますか?

1.多言語対応125以上の言語で領収書を処理したり、 1つの文書で複数の言語を処理したりできます。

IronOCRはレシートのバーコードを読み取ることができますか?

2.バーコード読み取りバーコードとQRコードを自動的に検出して読み取ります。

コンピュータビジョンはレシート処理にどのように役立つのか?

3.コンピュータビジョン高度なテキスト検出を使用して、OCRの前にテキスト領域を特定します。

独自のレシート形式に対応したカスタムモデルをトレーニングすることはできますか?

4.カスタムトレーニング:特殊なレシートフォーマットに対応したカスタムフォントのトレーニング

大量処理のパフォーマンスを向上させるにはどうすればよいですか?

5.パフォーマンスの最適化:大量処理に対して マルチスレッド非同期処理を実装する。

// Example: Async receipt processing for high-volume scenarios
using IronOcr;
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;

class BulkReceiptProcessor
{
    static async Task Main()
    {
        var ocr = new IronTesseract();

        // Configure for optimal performance
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
        ocr.Configuration.UseMultiThreading = true;
        ocr.Configuration.ProcessorCount = Environment.ProcessorCount;

        // Process multiple receipts asynchronously
        var receiptFiles = Directory.GetFiles(@"C:\Receipts\", "*.jpg");
        var tasks = new List<Task<OcrResult>>();

        foreach (var file in receiptFiles)
        {
            tasks.Add(ProcessReceiptAsync(ocr, file));
        }

        // Wait for all receipts to be processed
        var results = await Task.WhenAll(tasks);

        // Aggregate results
        decimal totalAmount = 0;
        foreach (var result in results)
        {
            // Extract total from each receipt
            var match = System.Text.RegularExpressions.Regex.Match(
                result.Text, @"Total:?\s*\$?(\d+\.\d{2})");

            if (match.Success && decimal.TryParse(match.Groups[1].Value, out var amount))
            {
                totalAmount += amount;
            }
        }

        Console.WriteLine($"Processed {results.Length} receipts");
        Console.WriteLine($"Combined total: ${totalAmount:F2}");
    }

    static async Task<OcrResult> ProcessReceiptAsync(IronTesseract ocr, string filePath)
    {
        using (var input = new OcrInput(filePath))
        {
            // Apply preprocessing
            input.DeNoise();
            input.Deskew();
            input.EnhanceResolution(200);

            // Process asynchronously
            return await ocr.ReadAsync(input);
        }
    }
}
// Example: Async receipt processing for high-volume scenarios
using IronOcr;
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;

class BulkReceiptProcessor
{
    static async Task Main()
    {
        var ocr = new IronTesseract();

        // Configure for optimal performance
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
        ocr.Configuration.UseMultiThreading = true;
        ocr.Configuration.ProcessorCount = Environment.ProcessorCount;

        // Process multiple receipts asynchronously
        var receiptFiles = Directory.GetFiles(@"C:\Receipts\", "*.jpg");
        var tasks = new List<Task<OcrResult>>();

        foreach (var file in receiptFiles)
        {
            tasks.Add(ProcessReceiptAsync(ocr, file));
        }

        // Wait for all receipts to be processed
        var results = await Task.WhenAll(tasks);

        // Aggregate results
        decimal totalAmount = 0;
        foreach (var result in results)
        {
            // Extract total from each receipt
            var match = System.Text.RegularExpressions.Regex.Match(
                result.Text, @"Total:?\s*\$?(\d+\.\d{2})");

            if (match.Success && decimal.TryParse(match.Groups[1].Value, out var amount))
            {
                totalAmount += amount;
            }
        }

        Console.WriteLine($"Processed {results.Length} receipts");
        Console.WriteLine($"Combined total: ${totalAmount:F2}");
    }

    static async Task<OcrResult> ProcessReceiptAsync(IronTesseract ocr, string filePath)
    {
        using (var input = new OcrInput(filePath))
        {
            // Apply preprocessing
            input.DeNoise();
            input.Deskew();
            input.EnhanceResolution(200);

            // Process asynchronously
            return await ocr.ReadAsync(input);
        }
    }
}
$vbLabelText   $csharpLabel

レシートのスキャンでよくある問題にどう対処すればよいですか?

レシートのスキャンには特有の課題がありますが、 IronOCRはそれらの課題解決を支援します。

画質の悪いレシート画像にどう対処すればいいですか?

-低品質の画像フィルターウィザードを使用して、最適な前処理設定を自動的に見つけます。

歪んだり回転したりしたレシートの場合はどうでしょうか?

-傾いたり回転したりしたレシート:自動ページ回転検出機能により、正しい向きで印刷されます。

色あせたレシートやコントラストの低いレシートはどのように処理すればよいですか?

-色あせた、またはコントラストの低いテキスト:色補正および強調フィルターを適用します。

IronOCRは、しわくちゃになったり破損したりしたレシートにも対応できますか?

-しわくちゃまたは破損したレシート高度な前処理により、判読困難な画像からテキストを復元します。

さまざまなレシートのフォーマットやレイアウトを管理するにはどうすればよいですか?

レシートの形式は小売店によって大きく異なる。 IronOCRは柔軟なアプローチを提供します。

using IronOcr;
using System;
using System.Collections.Generic;
using System.Linq;

class ReceiptLayoutHandler
{
    static void Main()
    {
        var ocr = new IronTesseract();

        // Configure for different receipt layouts
        ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd;
        ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;

        using (var input = new OcrInput(@"complex_receipt.jpg"))
        {
            // Apply region-specific processing
            var cropRegion = new CropRectangle(x: 0, y: 100, width: 400, height: 800);
            input.AddImage(@"complex_receipt.jpg", cropRegion);

            // Process with confidence tracking
            var result = ocr.Read(input);

            // Parse using confidence scores
            var highConfidenceLines = result.Lines
                .Where(line => line.Confidence > 85)
                .Select(line => line.Text)
                .ToList();

            // Extract data with fallback strategies
            var total = ExtractTotal(highConfidenceLines) 
                        ?? ExtractTotalAlternative(result.Text);

            Console.WriteLine($"Receipt Total: {total}");
        }
    }

    static decimal? ExtractTotal(List<string> lines)
    {
        // Primary extraction method
        foreach (var line in lines)
        {
            if (line.Contains("TOTAL") && 
                System.Text.RegularExpressions.Regex.IsMatch(line, @"\d+\.\d{2}"))
            {
                var match = System.Text.RegularExpressions.Regex.Match(line, @"(\d+\.\d{2})");
                if (decimal.TryParse(match.Value, out var total))
                    return total;
            }
        }
        return null;
    }

    static decimal? ExtractTotalAlternative(string fullText)
    {
        // Fallback extraction method
        var pattern = @"(?:Total|TOTAL|Grand Total|Amount Due).*?(\d+\.\d{2})";
        var match = System.Text.RegularExpressions.Regex.Match(fullText, pattern);

        if (match.Success && decimal.TryParse(match.Groups[1].Value, out var total))
            return total;

        return null;
    }
}
using IronOcr;
using System;
using System.Collections.Generic;
using System.Linq;

class ReceiptLayoutHandler
{
    static void Main()
    {
        var ocr = new IronTesseract();

        // Configure for different receipt layouts
        ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd;
        ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;

        using (var input = new OcrInput(@"complex_receipt.jpg"))
        {
            // Apply region-specific processing
            var cropRegion = new CropRectangle(x: 0, y: 100, width: 400, height: 800);
            input.AddImage(@"complex_receipt.jpg", cropRegion);

            // Process with confidence tracking
            var result = ocr.Read(input);

            // Parse using confidence scores
            var highConfidenceLines = result.Lines
                .Where(line => line.Confidence > 85)
                .Select(line => line.Text)
                .ToList();

            // Extract data with fallback strategies
            var total = ExtractTotal(highConfidenceLines) 
                        ?? ExtractTotalAlternative(result.Text);

            Console.WriteLine($"Receipt Total: {total}");
        }
    }

    static decimal? ExtractTotal(List<string> lines)
    {
        // Primary extraction method
        foreach (var line in lines)
        {
            if (line.Contains("TOTAL") && 
                System.Text.RegularExpressions.Regex.IsMatch(line, @"\d+\.\d{2}"))
            {
                var match = System.Text.RegularExpressions.Regex.Match(line, @"(\d+\.\d{2})");
                if (decimal.TryParse(match.Value, out var total))
                    return total;
            }
        }
        return null;
    }

    static decimal? ExtractTotalAlternative(string fullText)
    {
        // Fallback extraction method
        var pattern = @"(?:Total|TOTAL|Grand Total|Amount Due).*?(\d+\.\d{2})";
        var match = System.Text.RegularExpressions.Regex.Match(fullText, pattern);

        if (match.Success && decimal.TryParse(match.Groups[1].Value, out var total))
            return total;

        return null;
    }
}
$vbLabelText   $csharpLabel

レシートスキャンAPIに関して覚えておくべき重要なポイントは何ですか?

IronOCRのようなレシートスキャンAPIは、レシートからのデータ抽出を自動化するための信頼性の高いソリューションを提供します。高度なOCR技術を使用することで、企業は仕入先名、購入日、明細、価格、税金、合計金額などを自動的に抽出できます。 複数の言語、通貨、バーコードに対応しているため、企業は領収書管理を簡素化し、時間を節約し、データに基づいた意思決定を行うことができます。

IronOCRは、開発者が必要とする正確かつ効率的なテキスト抽出ツールを提供し、タスクの自動化と効率性の向上を実現します。 このライブラリの完全な機能セットには、さまざまなドキュメントタイプのサポートや、 メモリ使用量を98%削減するなどの最近の改善が含まれています。

前提条件を満たし、 IronOCRを統合することで、自動レシート処理のメリットを享受できます。 ライブラリのドキュメントサンプルトラブルシューティングガイドは、スムーズな導入を保証します。

詳細については、ライセンスページをご覧いただくか、 C# Tesseract OCR チュートリアルをご覧ください。

よくある質問

C#でOCRを使って領収書データの抽出を自動化するにはどうすればよいですか?

C#では、IronOCRを使用して領収書からラインアイテム、価格、税金、総額などの主要な詳細を高精度で抽出することができ、データ抽出を自動化できます。

C#で領収書スキャンプロジェクトを設定するための前提条件は何ですか?

C#で領収書スキャンプロジェクトを設定するには、Visual Studio、基本的なC#プログラミング知識、およびプロジェクトにインストールされたIronOCRライブラリが必要です。

Visual StudioでNuGetパッケージマネージャーを使用してOCRライブラリをインストールするにはどうすればよいですか?

Visual Studioを開いて、ツール > NuGetパッケージマネージャー > ソリューションのNuGetパッケージを管理する に移動し、IronOCRを検索してプロジェクトにインストールします。

Visual Studioコマンドラインを使用してOCRライブラリをインストールできますか?

はい、Visual Studioでパッケージマネージャーコンソールを開き、Install-Package IronOcr コマンドを実行することで、IronOCRをインストールできます。

OCRを使用して領収書全体のテキストを抽出するにはどうすればよいですか?

領収書全体のテキストを抽出するには、IronOCRを使用して領収書の画像全体に対してOCRを実行し、その抽出されたテキストをC#コードで出力します。

領収書スキャンAPIにはどのようなメリットがありますか?

IronOCRのような領収書スキャンAPIは、データ抽出の自動化、手動エラーの最小化、生産性の向上、支出パターンの洞察を提供し、より良いビジネス意思決定を可能にします。

OCRライブラリは複数の言語や通貨をサポートしていますか?

はい、IronOCRは複数の言語、通貨、領収書フォーマットをサポートしており、グローバルなアプリケーションに最適です。

画像からテキストを抽出する際のOCRライブラリの精度はどのくらいですか?

IronOCRは、先進のOCRアルゴリズム、コンピュータビジョン、機械学習モデルを使用して、高精度を保証します。困難なシナリオでも信頼性があります。

OCRを使用して領収書からどのようなデータを抽出できますか?

IronOCRは、ラインアイテム、価格、税額、総額、その他の領収書の詳細を抽出することができます。

レシート解析の自動化はビジネスプロセスをどのように改善できますか?

IronOCRを使用して領収書解析を自動化することで、手動入力を削減し、正確なデータ収集が可能になり、データ駆動型の意思決定をサポートします。

Kannaopat Udonpant
ソフトウェアエンジニア
ソフトウェアエンジニアになる前に、Kannapatは北海道大学で環境資源の博士号を修了しました。博士号を追求する間に、彼はバイオプロダクションエンジニアリング学科の一部である車両ロボティクスラボラトリーのメンバーになりました。2022年には、C#のスキルを活用してIron Softwareのエンジニアリングチームに参加し、IronPDFに注力しています。Kannapatは、IronPDFの多くのコードを執筆している開発者から直接学んでいるため、この仕事を大切にしています。同僚から学びながら、Iron Softwareでの働く社会的側面も楽しんでいます。コードやドキュメントを書いていない時は、KannapatはPS5でゲームをしたり、『The Last of Us』を再視聴したりしていることが多いです。

アイアンサポートチーム

私たちは週5日、24時間オンラインで対応しています。
チャット
メール
電話してね