IronOCR ile Kırpılmış Bölgeler ve Dikdörtgenler
IronOCR ile PDF'ler üzerinde içerik alanlarını nasıl ayarlayabilirim?
ContentAreas ve PDF'ler
OcrInput.LoadPdf ve LoadPdfPage yöntemleri, bir İçerik Alanı ekleme seçeneğine sahiptir.
Soru - PDF'ler piksel cinsinden ölçülmezken, içerik alanımın ne kadar büyük olduğunu nasıl bilebilirim?
Seçenek 1
OcrInput.TargetDPI varsayılan değeri 225'tir - bu, PDF görüntüsünün piksel cinsinden boyutunu belirler. IronOCR bunu okuyacaktır.
Seçenek 2 (ideal kullanım durumu)
- PDF şablonunuzla birlikte
OcrInput.LoadPdf()kullanın. - Girdinin genişliğini ve yüksekliğini almak için
OcrInput.GetPages()kullanın. - OCR motorunun okuyacağı tam görüntüyü almak için
OcrInput.GetPages().First().ToBitmap()kullanın. - Şimdi, dışa aktarılan görüntüden İçerik Alanlarını piksel cinsinden ölçebilirsiniz.
- Hedeflenen koordinatlar, belirli bir OCR bölgesi için kullanılabilir.
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");
}Imports System.Linq ' Needed for First()
Imports IronOcr
Dim ocr As New IronTesseract()
Using input As 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 UsingSonuç:
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
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Define the content area rectangle with specific pixel coordinates
Dim contentArea As New Rectangle With {
.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
Dim result = ocr.Read(input)
' Optionally, print the OCR result
Console.WriteLine(result.Text)
End UsingAPI Referansı: OcrInput|OcrInput.Page

Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapılandırılmış, görsel olarak çekici kılavuzlar oluşturmayı seviyor.