ליבה API

ליבת API

דף זה מתאר את מחזור החיים של האובייקט ואת התנהגות החריגות של ארבעת הסוגים הליבתיים: AsposeOcr, OcrInput, OcrOutput ו-RecognitionResult.


מחזור החיים של OcrInput

OcrInput מיישם IDisposable ויש ליצור אותו בהצהרת using. הבנאי שלו מקבל InputType (InputType.SingleImage או InputType.PDF), ו-OcrInput.Add(string) מצרפת בתור נתיב קובץ אחד בכל פעם — אותו מופע של OcrInput יכול להכיל קבצים מרובים מאותו סוג קלט.

using Aspose.OCR;

using var input = new OcrInput(InputType.SingleImage);
input.Add("page-1.jpg");
input.Add("page-2.png");

זיהוי וקריאת OcrOutput

AsposeOcr.Recognize(OcrInput) מחזיר OcrOutput, שהוא List<RecognitionResult> — ניתן לאינדקס כמו כל רשימה, עם RecognitionResult אחד לכל תמונה (ל-InputType.SingleImage, אחד לכל קובץ שנוסף) או לכל עמוד PDF (ל-InputType.PDF).

var api = new AsposeOcr();
OcrOutput output = api.Recognize(input);
RecognitionResult first = output[0];

RecognitionResult והסוג המקונן LinesResult

RecognitionResult.LinesResult היא מחלקה מקוננת — הפנה אליה כ־RecognitionResult.LinesResult, ולא כסוג עצמאי. כל RecognitionResult חושפת:

  • RecognitionText — הטקסט המוכר המלא עבור אותה תמונה או עמוד, כאשר השורות מצורפות בעזרת מעברי שורה.
  • RecognitionLinesResult — List<RecognitionResult.LinesResult> אחד לכל שורת טקסט מזוהה, שכל אחד כולל TextInLine (טקסט השורה) ו-Line (‏System.Drawing.Rectangle שמספקת את קואורדינטות הפיקסלים של השורה בתמונה המקורית).
RecognitionResult result = output[0];
Console.WriteLine(result.RecognitionText);

foreach (RecognitionResult.LinesResult line in result.RecognitionLinesResult)
{
    System.Drawing.Rectangle bounds = line.Line;
    Console.WriteLine($"x={bounds.X}, y={bounds.Y}: {line.TextInLine}");
}

חריגות

AsposeOcr.Recognize(OcrInput) מאמת את הקלט שלו לפני הרצת ההכרה:

ConditionException
input הוא nullArgumentNullException
input’s InputType אינו SingleImage או PDFNotSupportedException
נתיב שנוסף באמצעות OcrInput.Add() אינו קיים על הדיסקFileNotFoundException

הבדיקות האלה מתבצעות לפני כל חישוב מודל, ולכן קלט שגוי נכשל מיידית במקום אחרי מעבר הכרה חלקי.


טיפים ושיטות עבודה מומלצות

  • OcrOutput ריק (Count == 0) אם OcrInput אין קבצים שנוספו — בדוק Count לפני אינדוקס.
  • RecognitionResult.LinesResult מקונן בתוך RecognitionResult; שם הסוג ברמת העליון LinesResult לבדו אינו סוג שניתן לפתור מחוץ למקוננות הזו.

בעיות נפוצות

בעיהסיבהתיקון
ArgumentNullException על Recognize()null נמסר במקום OcrInputתמיד צור OcrInput לפני קריאה ל-Recognize()
NotSupportedException על Recognize()OcrInput נבנה עם סוג קלט שאינו SingleImage/PDFרק InputType.SingleImage ו-InputType.PDF תקפים
FileNotFoundException על Recognize()נתיב בתור אינו קייםאמת את נתיבי הקבצים לפני קריאה ל-OcrInput.Add()

FAQ

האם RecognitionResult.LinesResult היא מחלקה ברמת העליון משלה?

לא — היא מקוננת בתוך RecognitionResult. הפנה אליה כ־RecognitionResult.LinesResult.

האם OcrOutput מבטיח סדר עמודים עבור קבצי PDF?

כן — עבור InputType.PDF, OcrOutput מחזיר RecognitionResult אחד לכל עמוד לפי סדר המקור.

מה קורה אם אני קורא ל-Recognize() עם OcrInput ריק?

זה מחזיר OcrOutput עם Count == 0 במקום לזרוק.


סיכום API Reference

מחלקה/מתודהתיאור
AsposeOcr.Recognize(OcrInput)מאמת ומזהה; זורק את ArgumentNullException, NotSupportedException או FileNotFoundException כאשר הקלט אינו תקין
OcrInput.OcrInput(InputType)בונה קונטיינר קלט עבור סוג קלט אחד
OcrInput.Add(string)מכניס נתיב קובץ לתור
OcrInput.Dispose()משחרר משאבים (דרך IDisposable)
OcrOutputList<RecognitionResult> מוחזר על ידי Recognize()
RecognitionResult.RecognitionTextהטקסט המלא שהזוהה עבור תמונה/עמוד אחד
RecognitionResult.RecognitionLinesResultList<RecognitionResult.LinesResult>
RecognitionResult.LinesResult.TextInLineטקסט מזוהה לשורה אחת
RecognitionResult.LinesResult.LineSystem.Drawing.Rectangle תיבת גבול לשורה אחת

ראה גם

 עברית