IronOCR ile İçerik Alanlarını ve Dikdörtgenlerini Kırpma

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronOCR ile PDF'lerde içerik alanlarını nasıl belirlerim?

ContentAreas ve PDFler

OcrInput.LoadPdf ve LoadPdfPage metodlarinin tamami bir ContentArea ekleme secenegine sahiptir.

Soru - İçerik alanımın ne kadar büyük olduğunu nasıl bilirim çünkü PDFler piksel olarak boyutlandırılmamıştır, ancak içerik alanları genellikle piksel cinsinden ölçülür?

Seçenek 1

OcrInput.TargetDPI varsıyılan 225'tir - bu, PDF görüntü boyutunu piksel cinsinden belirler. IronOCR bunu okuyacaktır.

Seçenek 2 (ideal kullanım durumu)

  1. PDF sablonunuzla OcrInput.LoadPdf() kullanin.
  2. Girdinin genisligini ve yuksekligini elde etmek icin OcrInput.GetPages() kullanin.
  3. OCR motorunun okuyacagi kesin görüntüyu elde etmek icin OcrInput.GetPages().First().ToBitmap() kullanin.
  4. Artık, dışa aktarılan görüntüden ContentArea'ları piksel cinsinden ölçebilirsiniz.
  5. Hedeflenen koordinatlar, belirli bir OCR bölgesi için kullanılabilir (Bkz. Nihai Sonuç).

Bilgilerinizi almak için:

using System.Linq;  // Needed for First()
using IronOcr;

var ocr = new IronTesseract();
using (var input = new OcrInput())
{
    // Load the PDF document
    input.LoadPdf("example.pdf");

    // Save the first page as a bitmap to measure it
    input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp");

    // Get the dimensions of the first page
    var width = input.GetPages().First().Width;
    var height = input.GetPages().First().Height;

    // Optionally, output the dimensions to understand the scale
    Console.WriteLine($"Width: {width}px, Height: {height}px");
}
using System.Linq;  // Needed for First()
using IronOcr;

var ocr = new IronTesseract();
using (var input = new OcrInput())
{
    // Load the PDF document
    input.LoadPdf("example.pdf");

    // Save the first page as a bitmap to measure it
    input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp");

    // Get the dimensions of the first page
    var width = input.GetPages().First().Width;
    var height = input.GetPages().First().Height;

    // Optionally, output the dimensions to understand the scale
    Console.WriteLine($"Width: {width}px, Height: {height}px");
}
Imports System.Linq ' Needed for First()
Imports IronOcr

Private ocr = New IronTesseract()
Using input = New OcrInput()
	' Load the PDF document
	input.LoadPdf("example.pdf")

	' Save the first page as a bitmap to measure it
	input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp")

	' Get the dimensions of the first page
	Dim width = input.GetPages().First().Width
	Dim height = input.GetPages().First().Height

	' Optionally, output the dimensions to understand the scale
	Console.WriteLine($"Width: {width}px, Height: {height}px")
End Using
$vbLabelText   $csharpLabel

Sonuç:

using IronOcr;
using IronSoftware.Drawing; // Needed for Rectangle

var ocr = new IronTesseract();
using (var input = new OcrInput())
{
    // Define the content area rectangle with specific pixel coordinates
    var contentArea = new Rectangle
    { 
        X = 215, 
        Y = 1250, 
        Height = 280, 
        Width = 1335 
    };  //<-- the area you want in px

    // Load the specific content area of the PDF
    input.LoadPdf("example.pdf", contentArea: contentArea);

    // Perform OCR on the defined content area
    var result = ocr.Read(input);

    // Optionally, print the OCR result
    Console.WriteLine(result.Text);
}
using IronOcr;
using IronSoftware.Drawing; // Needed for Rectangle

var ocr = new IronTesseract();
using (var input = new OcrInput())
{
    // Define the content area rectangle with specific pixel coordinates
    var contentArea = new Rectangle
    { 
        X = 215, 
        Y = 1250, 
        Height = 280, 
        Width = 1335 
    };  //<-- the area you want in px

    // Load the specific content area of the PDF
    input.LoadPdf("example.pdf", contentArea: contentArea);

    // Perform OCR on the defined content area
    var result = ocr.Read(input);

    // Optionally, print the OCR result
    Console.WriteLine(result.Text);
}
Imports IronOcr
Imports IronSoftware.Drawing ' Needed for Rectangle

Private ocr = New IronTesseract()
Using input = New OcrInput()
	' Define the content area rectangle with specific pixel coordinates
	Dim contentArea = New Rectangle With {
		.X = 215,
		.Y = 1250,
		.Height = 280,
		.Width = 1335
	}

	' Load the specific content area of the PDF
	input.LoadPdf("example.pdf", contentArea:= contentArea)

	' Perform OCR on the defined content area
	Dim result = ocr.Read(input)

	' Optionally, print the OCR result
	Console.WriteLine(result.Text)
End Using
$vbLabelText   $csharpLabel

API Referansi: OcrInput|OcrInput.Page

Curtis Chau
Teknik Yazar

Curtis Chau, Bilgisayar Bilimleri alanında lisans derecesine sahiptir (Carleton Üniversitesi) ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirme üzerine uzmanlaşmıştır. Kullanıcı dostu ve estetik açıdan hoş arayüzler tasarlamaya tutkuyla bağlı olan Curtis, modern çerç...

Daha Fazlasını Oku
Başlamaya Hazır mısınız?
Nuget İndirmeler 5,585,834 | Sürüm: 2026.4 just released
Still Scrolling Icon

Hala Kaydiriyor musunuz?

Hızlı bir kanit mi istiyorsunuz? PM > Install-Package IronOcr
örnekleri çalıştır resminizin aranabilir metne donuşünü izleyin.