การอัตโนมัติการตรวจสอบคําหลักสําหรับไฟล์ภาพให้แน่ใจว่าข้อมูลภาพของคุณจะถูกแท็กอย่างต่อเนื่องและสามารถค้นพบได้ง่าย ด้วย Aspose.OCR สําหรับ .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 — Initialize Aspose.OCR และ Scan the Archive

Match the gist: สร้างมอเตอร์ 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 — การขยายการตรวจสอบ (ตัวเลือก แต่แนะนํา)

ใบมีดพิมพ์เพียง 1 boolean คุณสามารถปรับปรุงการรายงานและกรองในขณะที่รักษาแกน 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

สร้าง Runner PowerShell ที่เรียบง่าย 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 การทํางานทุกวันที่ 2am:

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

เข้าสู่ระบบออกไปยังไฟล์โดยการวางคําสั่งใน a .cmd ที่ redirects stdout/stderr:ImageArchiveKeywordAudit.exe >> C:\Path\To\Logs\audit-%DATE%.log 2>&1

แนวทางที่ดีที่สุด

  • ** حفظแหล่งคําหลักแบบแคนิค** حفظรายการของคุณใน Git หรือ CMDB; ตรวจสอบรายเดือน
  • การกําหนดค่าข้อความ OCR. Trim whitespace, unify hyphens และ Unicode look-alikes ก่อนที่จะจับคู่
  • ประสิทธิภาพ Tune. บัตรตามโฟลเดอร์ เพิ่มความสม่ําเสมอเฉพาะหลังจากวัด I/O และ CPU
  • คุณภาพใน, คุณภาพออก. การสแกนสะอาด (deskew/denoise) ปรับปรุงอัตราการแข่งขันอย่างมีนัยสําคัญ
  • ปริมาณการตรวจสอบ โปรดพิจารณาชุดคําหลักที่แยกต่างหากต่อการเก็บรวบรวม (เช่น “ Landscape”, “ผลิตภัณฑ์” และ “รูปแบบ”).
  • สามารถติดตามได้ حفظรายงาน CSV พร้อมตารางเวลาเพื่อเปลี่ยนประวัติและการกระจายอย่างรวดเร็ว

Troubleshooting

  • การส่งออก OCR ว่างเปล่า: ตรวจสอบแนวตั้งภาพและความต้านทาน; ลองรูปแบบอื่น ๆ (*.png, *.tif).
  • **ความล้มเหลว: ** เพิ่มตัวเลือกหรือซิงโครเมี่ยมหลาย / เสียงในรายการของคุณ (เช่น “บ้า” หรือ “ป้า”).
  • **ปัญหาการส่งผ่าน: ** จํากัด การทํางานร่วมกันหลีกเลี่ยงการสแกนส่วนเครือข่ายผ่านการเชื่อมต่อช้า

More in this category