IronOCR OCR 프로그램으로 이미지 텍스트 변환 시 영역 및 사각형 설정하기
IronOCR 사용하여 PDF에 콘텐츠 영역을 설정하는 방법은 무엇인가요?
콘텐츠 영역 및 PDF
OcrInput.LoadPdf 및 LoadPdfPage 메서드는 모두 ContentArea를 추가할 수 있는 옵션이 있습니다.
질문은 다음과 같습니다. PDF 파일의 크기는 픽셀 단위로 표시되지 않지만, 콘텐츠 영역은 일반적으로 픽셀 단위로 측정되는데, 콘텐츠 영역의 크기를 어떻게 알 수 있을까요?
옵션 1
OcrInput.TargetDPI의 기본값은 225이며, 이는 PDF 이미지의 크기를 픽셀로 지정합니다. IronOCR 이를 읽을 것입니다.
옵션 2 (이상적인 사용 사례)
- PDF 템플릿에
OcrInput.LoadPdf()을 사용합니다. - 입력의 너비와 높이를 얻기 위해
OcrInput.GetPages()을 사용합니다. - OCR 엔진이 읽을 정확한 이미지를 얻기 위해
OcrInput.GetPages().First().ToBitmap()을 사용합니다. - 이제 내보낸 이미지에서 ContentAreas를 픽셀 단위로 측정할 수 있습니다.
- 목표 좌표는 특정 OCR 영역에 사용할 수 있습니다(최종 결과 참조).
정보를 얻으려면:
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
최종 결과:
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
API 참조: OcrInput | OcrInput.페이지

