עיבוד תיעוד אוטומטי יכול לשפר באופן משמעותי את הפרודוקטיביות והדיוק בתעשיות שונות, מהשירותים המשפטיים והפיננסיים לטיפול רפואי וייצור.כלי חזק אחד למשימה זו הוא Aspose.OCR עבור .NET, המאפשר למפתחים לחלץ טקסט מסמכים שנבדקו ותמונות עם דיוק גבוה.המדריך הזה מראה כיצד להגדיר ולהשתמש באספוס.OCR עבור ,NET כדי לאוטומציה של משימות מעבדות תיאור, כולל פעולות OCR סדרה ואינטגרציה עם מערכות צד שלישי.
דוגמה מלאה
להלן דוגמה מקיפה (מארחת כמקור) המראה כיצד להשתמש Aspose.OCR עבור .NET כדי לבצע OCR על תמונות מרובות בתיקייה ולשמור את הטקסט שנלקח לתוך קבצי טקסט המתאימים.
הדרכה צעד אחר צעד
שלב 1: התחל את מנוע OCR
ליצור ולהגדיר את מנוע OCR. הגדר את השפה הרצויה (אנגלית בדוגמה זו).
// Step 1: Initialize the OCR Engine
using Aspose.Ocr;
using (Ocr ocrEngine = new Ocr())
{
// Set language and other configurations if needed
ocrEngine.Language = Language.English;
// (Continue with steps below inside this using block)
}
שלב 2: להעלות תמונות לעיבוד
הגדר תיקיות כניסה/יציאה, לוודא כי תיבת הכניסה קיימת, ולרשום קבצי תמונה.
// Step 2: Load Images for Processing
string inputDirectory = @"path\to\input\images";
string outputDirectory = @"path\to\output\text";
if (!Directory.Exists(outputDirectory))
{
Directory.CreateDirectory(outputDirectory);
}
// Get all files from the input directory (same pattern as the gist)
// TIP: to restrict to specific formats, replace "*.*" with "*.png" or "*.jpg"
string[] imageFiles = Directory.GetFiles(
inputDirectory,
"*.*",
SearchOption.TopDirectoryOnly
);
שלב 3: ביצוע OCR על כל תמונה
להדביק את הקבצים ולהכיר את הטקסט באמצעות RecognizeImage(string path)
.
// Step 3: Perform OCR on Each Image
foreach (string imageFile in imageFiles)
{
try
{
// Recognize text from the image (exactly as in the gist)
string recognizedText = ocrEngine.RecognizeImage(imageFile);
// Proceed to Step 4: save text to disk...
}
catch (Exception ex)
{
Console.WriteLine($"Error processing {imageFile}: {ex.Message}");
}
}
שלב 4: שמור את הטקסט שנלקח לתוך קבצים
יצירת קואורדינט .txt
קובץ עבור כל תמונה מעובדת.
// Step 4: Save Extracted Text to Files
string outputFilePath = Path.Combine(
outputDirectory,
Path.GetFileNameWithoutExtension(imageFile) + ".txt"
);
File.WriteAllText(outputFilePath, recognizedText);
Console.WriteLine($"Processed: {imageFile} -> {outputFilePath}");
טיפים & Tweaks
- פורמטים מסננים: השתמש בדפוסים כגון
"*.png"
או"*.jpg"
לשחרר קבצים שאינם תמונה. - תת-קרקעיות • שינוי
SearchOption.TopDirectoryOnly
לSearchOption.AllDirectories
.
- תת-קרקעיות • שינוי
- היציאה ריקה של הספינה: אם
string.IsNullOrWhiteSpace(recognizedText)
להירשם ולהמשיך.
- היציאה ריקה של הספינה: אם
- חוטים מקבילים**: שימוש
Parallel.ForEach(imageFiles, file => { ... })
עבור ריצה מהירה יותר (מוח I / O ורישיון).
- חוטים מקבילים**: שימוש
על ידי עמידה בשלבים אלה, אתה יכול אוטומטי להוסיף OCR עם Aspose.OCR עבור .NET ולייצוא קבצי טקסט טהור לעיבוד נמוך.