画像アーカイブのキーワード監査の自動化は、視覚データが一貫してタグされ、簡単に見つけることができることを保証します. Aspose.OCR for .NET を使用すると、画像から内蔵/見えるテキストを読み、コントロールされたキーボードリストに反して確認することができます.その後、欠けているものを報告します。

完全例

原則

  • .NET 8 (または .NET 6+) SDK がインストールされています。
  • NuGet アクセスインストール Aspose.OCR.
  • 監査のための画像フォルダー(例えば、 C:\Path\To\ImageArchive).
  • (オプション) あなたが評価制限を超える計画がある場合、Asposeライセンスファイル。

プロジェクトを作成 & パッケージを追加

dotnet new console -n ImageArchiveKeywordAudit -f net8.0
cd ImageArchiveKeywordAudit
dotnet add package Aspose.OCR

ステップ1 - キーワードリストの準備

あなたの画像が含まれるべきカノニックキーワードを決定します. gistでは、単純さのためのハードコードが表示されます:

// Exact shape used in the gist
List<string> keywords = new List<string>
{
    "mountains", "beaches", "forests", "landscape"
};

タイプ(オプション): キーワードを保存する keywords.txt (ひとつ一つ)そしてそれらを積み重ねる。 List<string> 回収を避けるための時間です。

ステップ2 - Aspose.OCR を開始し、アーカイブをスキャンする

ギフトと一致する: OCR エンジンを作成し、画像をリスト、それぞれのファイルをOCR、キーワードの存在をチェックします。

using System;
using System.Collections.Generic;
using System.IO;
using Aspose.Ocr;

namespace ImageArchiveKeywordAudit
{
    class Program
    {
        static void Main(string[] args)
        {
            // Path to the image archive directory (edit to your folder)
            string imageDirectory = @"C:\Path\To\ImageArchive";

            // Keyword list for auditing (matches the gist approach)
            List<string> keywords = new List<string>
            {
                "mountains", "beaches", "forests", "landscape"
            };

            // Initialize Aspose.OCR API (license is optional)
            // new License().SetLicense("Aspose.Total.lic");
            using (AsposeOcr api = new AsposeOcr())
            {
                // Process each JPG in the directory (same filter style as the gist)
                foreach (string imagePath in Directory.GetFiles(imageDirectory, "*.jpg"))
                {
                    // Extract text from the image
                    string extractedText = api.RecognizeImageFile(imagePath);

                    // Audit the extracted text against the keyword list
                    bool containsKeywords = AuditText(extractedText, keywords);

                    // Output the results
                    Console.WriteLine($"Image: {imagePath} - Contains Keywords: {containsKeywords}");
                }
            }
        }

        // Method to audit extracted text against a list of keywords (as in gist)
        static bool AuditText(string text, List<string> keywords)
        {
            foreach (string keyword in keywords)
            {
                if (text.Contains(keyword, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
            return false;
        }
    }
}

ステップ3 - 監査を延長する(オプションですが推奨)

ガムはボーレーンだけを印刷します. 同じOCRコアを保持しながら、レポートとフィルタリングを改善することができます。

3.A フィルター 複数の画像タイプ

// Replace the single GetFiles with this multi-pattern approach
string[] patterns = new[] { "*.jpg", "*.jpeg", "*.png", "*.tif", "*.tiff", "*.bmp" };
var imageFiles = new List<string>();
foreach (var pattern in patterns)
    imageFiles.AddRange(Directory.GetFiles(imageDirectory, pattern, SearchOption.TopDirectoryOnly));

3.b どのキーワードが合致/欠けているかを記録する

// After OCR:
var matched = new List<string>();
var missing = new List<string>();

foreach (var k in keywords)
    (extractedText.IndexOf(k, StringComparison.OrdinalIgnoreCase) >= 0 ? matched : missing).Add(k);

Console.WriteLine($"Image: {Path.GetFileName(imagePath)} | Matched: [{string.Join(", ", matched)}] | Missing: [{string.Join(", ", missing)}]");

3.c CSV レポートを書く

string reportPath = Path.Combine(imageDirectory, "audit-report.csv");
bool writeHeader = !File.Exists(reportPath);

using (var sw = new StreamWriter(reportPath, append: true))
{
    if (writeHeader)
        sw.WriteLine("Image,ContainsKeywords,Matched,Missing");

    sw.WriteLine($"\"{Path.GetFileName(imagePath)}\",{matched.Count > 0},\"{string.Join(";", matched)}\",\"{string.Join(";", missing)}\"");
}

ステップ4 - PowerShell または Batch から実行

シンプルなPowerShell Runnerを作成する run-audit.ps1:

# Adjust paths as needed
$solutionRoot = "C:\Path\To\ImageArchiveKeywordAudit"
$imageDir     = "C:\Path\To\ImageArchive"

# Build and run
dotnet build "$solutionRoot" -c Release
& "$solutionRoot\bin\Release\net8.0\ImageArchiveKeywordAudit.exe"

オプション: 議論を受け入れるためにプログラムを変更する場合は、以下のように実行します。ImageArchiveKeywordAudit.exe "C:\Images" "C:\keywords.txt"

ステップ5 - スケジュール 繰り返し監査(Windows Task Scheduler)

利用 schtasks 毎日2時ごろで走る:

schtasks /Create /TN "ImageKeywordAudit" /TR "\"C:\Path\To\ImageArchiveKeywordAudit\bin\Release\net8.0\ImageArchiveKeywordAudit.exe\"" /SC DAILY /ST 02:00

コマンドを入力してファイルにログ出力 .cmd stdout/stderr をリダイレクトする:ImageArchiveKeywordAudit.exe >> C:\Path\To\Logs\audit-%DATE%.log 2>&1

ベストプラクティス

  • カノニカルキーワードソースを保存する リストを Git または CMDB に保存し、毎週レビューします。
  • OKRテキストを正常化します。 ホワイトスペース、ユニフィーハイフェンズ、Unicodeの表示アリックスを組み合わせる前にトリム。
  • Tune performance. フォルダーによってバッチ; I/O と CPU を測定した後にのみパラレルを追加します。
  • ** 品質、品質が表示されます。** クリーンスキャン(デッキ/デノイズ)は試合率を大幅に改善します。
  • ** 監査範囲.** 各コレクションごとに別々のキーワードセットを考慮する(例えば、「フィールドキャップ」、「製品」、「フォーム」)。
  • 追跡性. CSV レポートをタイムステンブルで保存して、歴史を変更し、迅速に分散します。

Troubleshooting

  • ** 空の OCR 出力:** 画像のオリエンテーションとコントロールを確認し、別のフォーマットを試してみてください(*.png, *.tif).
  • 偽ネガティブ: リストに複数の/音のバージョンまたは同義語を追加する(例えば「ビーチ」、「ビーズ」)。
  • Throughput 問題: 競争の実行を制限し、ゆっくりリンクを介してネットワーク シェアをスキャンすることを避ける。

More in this category