이미지 아카이브에 대한 키워드 검토를 자동화하면 시각 데이터가 일관되게 표시되고 쉽게 찾을 수 있습니다. Aspose.OCR for .NET를 사용하면 이미지에서 삽입/시각적인 텍스트를 읽고 통제된 키어드 목록에 대해 확인할 수 있으며, 그 후에 실패한 것을 보고합니다.이 가이드는 끝에 gist와 일치하는 구체적이고 실행 가능한 단계로 작업 흐름을 향상시킵니다.

완전한 예제

원칙

  • .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 엔진을 만들고, 이미지를 나열하고, 각 파일의 O CR를 확인하고 키워드의 존재에 대해 확인합니다.

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 작업 일정)

사용하기 schtasks 매일 오후 2시에 실행하십시오 :

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

로그 출력에 파일을 입력하여 명령을 삽입하여 a .cmd 그것은 stdout/stderr를 리디렉션합니다 :ImageArchiveKeywordAudit.exe >> C:\Path\To\Logs\audit-%DATE%.log 2>&1

모범 사례

  • ** 캐논 키워드 출처를 유지하십시오.** 목록을 Git 또는 CMDB로 저장; 매주 검토합니다.
  • OCR 텍스트를 정상화하십시오. 화이트 스페이스, unify hyphens 및 Unicode look-alikes를 조정하기 전에.
  • Tune 성능. 폴더에 따라 배치; I/O 및 CPU를 측정한 후에만 병렬성을 추가합니다.
  • ** 품질 내에서, 밖에서.** 깨끗한 스캔 (Deskw/denoise)은 상당히 경기율을 향상시킵니다.
  • Audit scope. 각 컬렉션에 따라 개별 키워드 세트를 고려하십시오 (예를 들어, “landscape”, “product” 또는 “forms”).
  • ** 추적 가능.** CSV 보고서를 시간표로 유지하여 역사 변경 및 빠른 차이를 제공합니다.

Troubleshooting

  • ** 빈 OCR 출력:** 이미지 방향 및 대조를 확인; 다른 형식을 시도하십시오 (*.png, *.tif).
  • ** 가짜 부정:** 목록에 다중/소리 변형 또는 동의어를 추가하십시오 (예를 들어, “비치”, “ 비치”).
  • Throughput 문제: 경쟁 실행을 제한; 느린 링크를 통해 네트워크 주식을 스캔하는 것을 피하십시오.

More in this category