レシートスキャンAPI: C#とIronOCRを使用してレシートからデータを抽出する
レシートスキャン API は、OCR テクノロジーを使用してレシートからのデータ抽出を自動化し、手動入力エラーを大幅に削減し、処理を高速化します。 このガイドでは、組み込みの画像前処理と複数の形式のサポートを使用して、C# で IronOCR を使用してレシート画像からベンダー名、日付、品目、価格、合計を正確に抽出する方法を説明します。
領収書のスキャンに IronOCR を選ぶ理由
IronOCR は、スキャンされたドキュメント、画像、PDF から信頼性の高いテキスト抽出を提供する柔軟なOCR ライブラリです。 高度なアルゴリズム、コンピューター ビジョン、機械学習モデルを備えた IronOCR は、困難なシナリオでも高い精度を保証します。 ライブラリは複数の言語とフォント スタイルをサポートしているため、グローバル アプリケーションに適しています。 IronOCR をアプリケーションに組み込むことで、データ入力とテキスト分析を自動化し、生産性を向上させることができます。
IronOCR はどのようにして領収書画像からテキストを抽出するのでしょうか?
IronOCR は、ドキュメント、写真、スクリーンショット、ライブ カメラ フィードからテキストを JSON 応答として取得します。 IronOCR は、高度なアルゴリズムと機械学習を使用して画像データを分析し、文字を認識し、機械が読み取り可能なテキストに変換します。 このライブラリは、優れた精度を実現するために独自の改良が加えられたTesseract 5 テクノロジーを使用しています。
IronOCR が領収書処理に優れている理由
IronOCR は、低品質のスキャン、さまざまな領収書形式、さまざまな方向の処理に優れています。 内蔵の画像前処理フィルターにより、処理前に画像品質が自動的に向上し、しわくちゃになったり色あせた領収書でも最適な結果が得られます。
IronOCR を使用するには何が必要ですか?
IronOCR を使用する前に、次の前提条件が満たされていることを確認してください。
どのような開発環境がサポートされていますか?
1.開発環境: Visual Studio などの適切な IDE をインストールします。 IronOCR は、 Windows 、 Linux 、 macOS 、 Azure 、 AWSをサポートしています。
どのようなプログラミングスキルが必要ですか?
- C# の知識: 基本的な C# の理解は、コード例を変更するのに役立ちます。 IronOCR は簡単な例とAPI ドキュメントを提供します。
必要なソフトウェア依存関係は何ですか?
- IronOCR のインストール: NuGet パッケージ マネージャー経由でインストールします。 プラットフォーム固有の依存関係が必要になる場合があります。
ライセンスキーは必要ですか?
4.ライセンス キー (オプション) : 無料試用版をご利用いただけます。 実稼働環境での使用にはライセンスが必要です。
レシートスキャン用の新しい Visual Studio プロジェクトを作成するにはどうすればよいですか?
Visual Studio で新しいプロジェクトを開始するにはどうすればよいですか?
Visual Studio を開いて [ファイル] に移動し、[新規] にマウスを移動して [プロジェクト] をクリックします。
! Visual Studio IDE のファイル メニューが展開され、"新規 > プロジェクト"オプションが強調表示され、コード エディターに Excel ブックを読み込むための C# コードが表示されています。 新しいプロジェクト画像
どのプロジェクト テンプレートを選択すればよいですか?
コンソール アプリケーションを選択し、[次へ] をクリックします。 このテンプレートは、Web アプリケーションに実装する前に IronOCR を学習するのに最適です。
Visual Studio の"新しいプロジェクトの作成"ダイアログで、Windows、Linux、macOS のプラットフォーム オプションとともにコンソール アプリケーション テンプレートが選択されている様子 コンソールアプリケーション
レシートスキャナー プロジェクトにどのような名前を付ければよいでしょうか?
プロジェクト名と場所を入力し、"次へ"をクリックします。 " ReceiptScanner API"のようなわかりやすい名前を選択します。
! Visual Studio の新しいプロジェクト構成画面で、C# が選択され、ソリューション設定が表示されている"IronOCR"というコンソール アプリケーションを作成します。 プロジェクト設定
どの .NET Framework バージョンを選択すればよいですか?
最適な互換性を確保するには .NET 5.0 以降を選択し、[作成] をクリックします。
Visual Studio の"追加情報"ダイアログには、ターゲットフレームワークとして .NET 5.0 が選択され、プラットフォームオプションとして Linux、macOS、Windows、コンソールが表示されている。 ターゲットフレームワーク
プロジェクトに IronOCR をインストールするにはどうすればよいですか?
2 つの簡単なインストール方法があります:
NuGet パッケージ マネージャー メソッドを使用するにはどうすればよいですか?
ツール> NuGet パッケージ マネージャー>ソリューションの NuGet パッケージの管理に移動します。
! Visual Studio NuGet パッケージ マネージャーの設定ダイアログには、ソリューション エクスプローラーの C# プロジェクト構造とパッケージ ソース構成が表示されます。 NuGetパッケージマネージャー
IronOCRを検索してパッケージをインストールします。 英語以外のレシートの場合は、言語固有のパッケージをインストールします。
コマンドラインインストールを使用するにはどうすればよいですか?
1.ツール> NuGet パッケージ マネージャー>パッケージ マネージャー コンソールに移動します。
次のコマンドを入力します。
Install-Package IronOcr
! Visual Studio パッケージ マネージャー コンソール ウィンドウに、'Create PDF' というプロジェクトに対して実行されている NuGet コマンド 'PM> Install-Package IronOCR' が表示されています。 パッケージマネージャーコンソール
IronOCR を使用して領収書データをすばやく抽出するにはどうすればよいですか?
わずか数行のコードで領収書データを抽出します。
今すぐ NuGet で PDF を作成してみましょう:
NuGet パッケージ マネージャーを使用して IronOCR をインストールします
このコード スニペットをコピーして実行します。
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}%"); }実際の環境でテストするためにデプロイする
領収書画像から構造化データを抽出するにはどうすればよいですか?
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}");
}
}
}レシートのスキャン精度を向上させる技術は何ですか?
正確な領収書スキャンのための重要なテクニック: -文字ホワイトリスト: 認識を予想される文字に制限します -画像前処理:傾き補正、解像度向上、ノイズ除去を使用します -パターンマッチング:正規表現を使用して構造化データを抽出します -信頼度スコアリング:認識の信頼度に基づいて結果を検証します
! PDF から抽出した請求書データを表示する Visual Studio デバッグ コンソール。説明、数量、価格、税金、合計を含む項目が表示されます。 出力
領収書の内容全体を抽出するにはどうすればよいですか?
書式を保持したまま領収書の完全な内容を抽出します。
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");
}
}
}! PDF から抽出した請求書データを表示する Visual Studio デバッグ コンソール。説明、数量、価格、税金、合計を含む項目が表示されます。 領収書スキャン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);
}
}
}領収書のスキャンに関する一般的な課題にどう対処すればよいですか?
領収書のスキャンには特有の課題がありますが、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;
}
}レシートスキャン 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を使用して領収書解析を自動化することで、手動入力を削減し、正確なデータ収集が可能になり、データ駆動型の意思決定をサポートします。






