Çekirdek API

Temel API

Bu sayfa, dört çekirdek tipin nesne yaşam döngüsü ve istisna davranışını kapsar: AsposeOcr, OcrInput, OcrOutput ve RecognitionResult.


OcrInput Yaşam Döngüsü

OcrInput, IDisposable‘i uygular ve bir using ifadesi içinde oluşturulmalıdır. Yapıcı bir InputType (InputType.SingleImage veya InputType.PDF) alır ve OcrInput.Add(string) aynı anda bir dosya yolunu sıraya ekler — aynı OcrInput örneği aynı giriş tipindeki birden fazla dosyayı tutabilir.

using Aspose.OCR;

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

Tanıma ve OcrOutput Okuma

AsposeOcr.Recognize(OcrInput), bir OcrOutput döndürür; bu bir List<RecognitionResult>‘dır — herhangi bir liste gibi indekslenebilir, her görüntü başına bir RecognitionResult (InputType.SingleImage için, eklenen dosya başına bir) veya PDF sayfası başına bir (InputType.PDF için).

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

RecognitionResult ve İç İçe LinesResult Tipi

RecognitionResult.LinesResult, iç içe bir sınıftır — ona RecognitionResult.LinesResult olarak başvurun, bağımsız bir tip olarak değil. Her RecognitionResult şunları ortaya çıkar:

  • RecognitionText — o görüntü ya da sayfa için tanınan tam metin, satırlar satır sonlarıyla birleştirilmiş.
  • RecognitionLinesResult — bir List<RecognitionResult.LinesResult>, tespit edilen her metin satırı için bir giriş, her biri TextInLine (satırın metni) ve Line (kaynak görüntüdeki satırın piksel koordinatlarını veren bir System.Drawing.Rectangle) içerir.
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}");
}

İstisnalar

AsposeOcr.Recognize(OcrInput) tanıma çalıştırmadan önce girdisini doğrular:

ConditionException
input nulldırArgumentNullException
input‘ın InputType SingleImage ya da PDF değilNotSupportedException
OcrInput.Add() aracılığıyla eklenen bir yol diskte mevcut değilFileNotFoundException

Bu kontroller herhangi bir model çıkarımından önce çalışır, böylece hatalı bir girdi kısmi tanıma işleminden sonra değil, hemen başarısız olur.


İpuçları ve En İyi Uygulamalar

  • OcrOutput OcrInput dosya eklenmemişse (Count == 0) boştur — indekslemeden önce Count kontrol edin.
  • RecognitionResult.LinesResult RecognitionResult içinde iç içe yer alır; üst düzey tip adı LinesResult tek başına bu iç içeliğin dışındaki bir bağlamda çözülebilir bir tip değildir.

Yaygın Sorunlar

SorunNedenDüzelt
ArgumentNullException Recognize() üzerindenull bir OcrInput yerine geçirildi.Recognize()‘i çağırmadan önce her zaman bir OcrInput oluşturun.
NotSupportedException Recognize() üzerindeOcrInput, SingleImage/PDF dışında bir girdi türüyle oluşturuldu.Yalnızca InputType.SingleImage ve InputType.PDF geçerlidir.
FileNotFoundException Recognize() üzerindeKuyruğa alınmış bir yol mevcut değilDosya yollarını OcrInput.Add() çağırmadan önce doğrulayın

FAQ

RecognitionResult.LinesResult kendi üst düzey sınıfı mı?

Hayır — RecognitionResult içinde iç içe. RecognitionResult.LinesResult olarak referans verin.

OcrOutput PDF’lerde sayfa sırasını garanti eder mi?

Evet — InputType.PDF için, OcrOutput kaynak sırada her sayfa için bir RecognitionResult döndürür.

Boş bir OcrInput ile Recognize() çağırırsam ne olur?

Hata fırlatmak yerine, Count == 0 içeren bir OcrOutput döndürür.


API Reference Özet

Sınıf/YöntemAçıklama
AsposeOcr.Recognize(OcrInput)Doğrular ve tanır; geçersiz girişte ArgumentNullException, NotSupportedException veya FileNotFoundException hatası fırlatır
OcrInput.OcrInput(InputType)Bir giriş türü için bir giriş konteyneri oluşturur
OcrInput.Add(string)Bir dosya yolunu kuyruğa ekler
OcrInput.Dispose()Kaynakları serbest bırakır (IDisposable aracılığıyla)
OcrOutputList<RecognitionResult>, Recognize() tarafından döndürülür
RecognitionResult.RecognitionTextTek bir görüntü/sayfa için tam tanınan metin
RecognitionResult.RecognitionLinesResultList<RecognitionResult.LinesResult>
RecognitionResult.LinesResult.TextInLineTek satır için tanınan metin
RecognitionResult.LinesResult.LineSystem.Drawing.Rectangle tek satır için sınırlama kutusu

Ayrıca Bakınız

 Türkçe