IronOCR로 C#에서 페이지 회전 감지하는 방법
IronOCR의 DetectPageOrientation 메서드는 PDF 문서와 이미지에서 페이지 회전 각도(0°, 90°, 180°, 270°)를 자동으로 식별합니다. 이 메서드는 각 페이지에 대해 RotationAngle 속성을 반환하여 정확한 텍스트 추출을 위한 신뢰도 점수를 제공하며 프로그램적으로 방향을 수정할 수 있도록 합니다.
페이지 회전 감지는 문서 페이지가 시계 방향 또는 반시계 방향으로 0, 90, 180 또는 270도 회전했는지 식별합니다. 이 정보는 올바른 방향으로 페이지를 표시하거나 처리하여 정확한 렌더링과 텍스트 추출을 보장합니다.
빠른 시작: 페이지 회전 식별에DetectPageOrientation 사용
이 예제는 PDF에서 IronOCR의 DetectPageOrientation를 사용하여 RotationAngle 속성에 접근하는 방법을 보여줍니다. 이는 최소한의 코드로 빠른 페이지 회전 감지 및 수정을 제공합니다.
-
1IronOCR를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
var rotationResults = new IronOcr.OcrInput().LoadPdf("doc.pdf").DetectPageOrientation(); Console.WriteLine(rotationResults.First().RotationAngle);Dim rotationResults = New IronOcr.OcrInput().LoadPdf("doc.pdf").DetectPageOrientation() Console.WriteLine(rotationResults.First().RotationAngle)Dim rotationResults = New IronOcr.OcrInput().LoadPdf("doc.pdf").DetectPageOrientation() Console.WriteLine(rotationResults.First().RotationAngle) -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronOCR 사용을 시작해보세요 무료 체험
최소 워크플로우(5단계)
- 페이지 회전을 감지하는 C# 라이브러리를 다운로드하세요.
- PDF 문서와 이미지를 불러와서 읽으세요.
DetectPageOrientation메서드를 사용하여 모든 페이지의 회전을 감지하세요- RotationAngle 속성에 액세스하여 페이지 회전을 수정합니다
- HighConfidence 속성에 액세스하여 엣지 케이스를 처리합니다
문서에서 페이지 회전을 어떻게 감지하나요?
문서를 로드한 후 DetectPageOrientation 메서드를 사용하여 각 페이지의 회전을 식별합니다. 이 메서드는 0, 90, 180, 270도를 지원합니다. 이 표준 회전을 초과하는 비뚤어진 이미지의 경우, IronOCR의 이미지 보정 필터에서 Deskew 메서드를 사용하세요. 감지된 각도를 사용하여 이미지를 원래 방향으로 다시 회전시키세요. 샘플 PDF를 사용해 봅시다.
using IronOcr;
using System;
using var input = new OcrInput();
// Load PDF document
input.LoadPdf("Clockwise90.pdf");
// Detect page rotation
var results = input.DetectPageOrientation();
// Ouput result
foreach(var result in results)
{
Console.WriteLine(result.PageNumber);
Console.WriteLine(result.HighConfidence);
Console.WriteLine(result.RotationAngle);
}using IronOcr;
using System;
using var input = new OcrInput();
// Load PDF document
input.LoadPdf("Clockwise90.pdf");
// Detect page rotation
var results = input.DetectPageOrientation();
// Ouput result
foreach(var result in results)
{
Console.WriteLine(result.PageNumber);
Console.WriteLine(result.HighConfidence);
Console.WriteLine(result.RotationAngle);
}Imports IronOcr
Imports System
Private input = New OcrInput()
' Load PDF document
input.LoadPdf("Clockwise90.pdf")
' Detect page rotation
Dim results = input.DetectPageOrientation()
' Ouput result
For Each result In results
Console.WriteLine(result.PageNumber)
Console.WriteLine(result.HighConfidence)
Console.WriteLine(result.RotationAngle)
Next resultImports IronOcr
Imports System
Private input = New OcrInput()
' Load PDF document
input.LoadPdf("Clockwise90.pdf")
' Detect page rotation
Dim results = input.DetectPageOrientation()
' Ouput result
For Each result In results
Console.WriteLine(result.PageNumber)
Console.WriteLine(result.HighConfidence)
Console.WriteLine(result.RotationAngle)
Next result감지 결과는 무엇을 의미하나요?
PageNumber: 페이지의 0 기반 인덱스.RotationAngle: 회전 각도(도 단위).Rotate메서드와 함께 사용하여 방향을 수정합니다.HighConfidence: 경계 상황에 대한 방향 결과의 신뢰도 수준.
언제 높은 신뢰도 값을 사용해야 하나요?
HighConfidence 속성은 회전 감지가 불확실할 수 있는 애매하거나 낮은 품질의 문서에서 중요합니다. 희소한 텍스트, 비정상적인 레이아웃, 또는 품질이 낮은 스캔된 문서는 종종 낮은 신뢰도 점수를 반환합니다. 이 경우, 감지 전에 추가 검증을 수행하거나 이미지 품질 보정 필터를 적용하세요.
이 값을 사용하여 예외 처리 전략을 구현하거나 신뢰도가 낮은 페이지에 대해 수동 검토를 수행하세요. 예를 들어, 신뢰도가 80% 아래로 떨어지면 페이지를 여러 방향으로 처리하고 OCR 결과를 비교하거나 수동 검토를 위해 플래그를 지정합니다. IronOCR의 컴퓨터 비전 기능은 어려운 문서에서 텍스트 영역을 더 정확하게 식별하는 데 도움을 줍니다.
감지된 회전을 어떻게 수정하나요?
회전 각도를 식별한 후 OCR 전에 방향을 수정하기 위해 OcrInput 객체에 대해 Rotate 메서드를 사용하세요. 이렇게 하면 최적의 텍스트 인식 정확도가 보장됩니다. 종합적인 방향 수정의 경우 이미지 방향 보정 가이드를 참조하세요. 다음은 수정 과정입니다:
// Apply rotation correction based on detection results
if (result.RotationAngle != 0)
{
input.Rotate(360 - result.RotationAngle); // Rotate back to 0°
}// Apply rotation correction based on detection results
if (result.RotationAngle != 0)
{
input.Rotate(360 - result.RotationAngle); // Rotate back to 0°
}' Apply rotation correction based on detection results
If result.RotationAngle <> 0 Then
input.Rotate(360 - result.RotationAngle) ' Rotate back to 0°
End If' Apply rotation correction based on detection results
If result.RotationAngle <> 0 Then
input.Rotate(360 - result.RotationAngle) ' Rotate back to 0°
End If추가 전처리가 필요한 문서의 경우, OCR 처리 전에 광범위한 문서 준비 메서드를 제공하는 OcrInput 클래스를 고려하세요.
검출 속도와 정밀도를 어떻게 맞춤화할 수 있나요?
DetectPageOrientation 메서드는 감지 세부 사항과 자원 사용을 제어하기 위한 선택적 매개변수를 수용합니다. OrientationDetectionMode 열거형을 제공하면 필요에 따라 탐지 속도 및 정확도를 조정할 수 있으며, 두 번째 maxDegreeOfParallelism 인수는 동시에 분석되는 페이지 수를 제한합니다.
다음은 그것을 구현하는 방법입니다:
using IronOcr;
using System;
using var input = new OcrInput();
// Load PDF document
input.LoadPdf("Clockwise90.pdf");
// Detect page rotation with Fast mode
var results = input.DetectPageOrientation(OrientationDetectionMode.Fast);
// Ouput result
foreach(var result in results)
{
Console.WriteLine(result.PageNumber);
Console.WriteLine(result.HighConfidence);
Console.WriteLine(result.RotationAngle);
}using IronOcr;
using System;
using var input = new OcrInput();
// Load PDF document
input.LoadPdf("Clockwise90.pdf");
// Detect page rotation with Fast mode
var results = input.DetectPageOrientation(OrientationDetectionMode.Fast);
// Ouput result
foreach(var result in results)
{
Console.WriteLine(result.PageNumber);
Console.WriteLine(result.HighConfidence);
Console.WriteLine(result.RotationAngle);
}Imports IronOcr
Imports System
Using input As New OcrInput()
' Load PDF document
input.LoadPdf("Clockwise90.pdf")
' Detect page rotation with Fast mode
Dim results = input.DetectPageOrientation(OrientationDetectionMode.Fast)
' Output result
For Each result In results
Console.WriteLine(result.PageNumber)
Console.WriteLine(result.HighConfidence)
Console.WriteLine(result.RotationAngle)
Next
End UsingImports IronOcr
Imports System
Using input As New OcrInput()
' Load PDF document
input.LoadPdf("Clockwise90.pdf")
' Detect page rotation with Fast mode
Dim results = input.DetectPageOrientation(OrientationDetectionMode.Fast)
' Output result
For Each result In results
Console.WriteLine(result.PageNumber)
Console.WriteLine(result.HighConfidence)
Console.WriteLine(result.RotationAngle)
Next
End Using어떤 검출 모드를 선택해야 하나요?
OrientationDetectionMode에 대해 네 가지 속도 옵션이 제공됩니다.
IronOcr.Extensions.AdvancedScan 패키지가 필요합니다. 이 옵션은 Windows x86 및 Mac ARM에서는 사용할 수 없습니다.- 빠름: 정확도가 낮은 고속 감지. 속도가 중요한 초안이나 대량 처리에 이상적입니다.
DetectPageOrientation의 기본값입니다. 멀티스레딩 지원과 함께 수천 페이지를 효율적으로 처리하며, 페이지당 할당하는 대신 워커 스레드당 하나의 엔진을 재사용하여 긴 문서에서 메모리 사용을 줄입니다. - 균형: 속도와 정확도의 균형. 생산 과제에 적합합니다. 성능을 유지하면서 정확도를 향상시키기 위해 고급 스캔 확장 기능을 사용합니다.
- 자세한: 낮은 속도, 높은 정확성. 정밀하거나 중요한 작업에 최적이며, 특히 복잡한 레이아웃이나 혼합 콘텐츠가 있는 문서에 적합합니다.
- 극한 정밀: 가장 느린 속도, 가장 높은 정확성. Detailed가 불충분하거나 텍스트가 심하게 기울어져 있고 왜곡된 경우에만 사용하세요.
방향 감지 중 메모리 한도 설정 방법은?
다중 페이지 입력에서는 방향 감지가 여러 페이지를 동시에 분석하며, 각 동시 페이지는 자체 엔진을 사용합니다. @maxDegreeOfParallelism 값을 전달하여 이 동시성을 제한하고 최대 메모리 사용을 억제하세요. 이는 메모리 제약이 있는 서버 및 컨테이너에서 유용하며, 문서를 병렬로 읽을 때 사용 가능한 MaxDegreeOfParallelism 제어를 반영합니다.
using IronOcr;
using System.Collections.Generic;
using var input = new OcrInput();
input.LoadPdf("scanned.pdf");
// Cap orientation detection to 2 pages at a time. The default is one per CPU core.
IEnumerable<OcrPageOrientationResult> orientation =
input.DetectPageOrientation(OrientationDetectionMode.Fast, maxDegreeOfParallelism: 2);using IronOcr;
using System.Collections.Generic;
using var input = new OcrInput();
input.LoadPdf("scanned.pdf");
// Cap orientation detection to 2 pages at a time. The default is one per CPU core.
IEnumerable<OcrPageOrientationResult> orientation =
input.DetectPageOrientation(OrientationDetectionMode.Fast, maxDegreeOfParallelism: 2);Imports IronOcr
Imports System.Collections.Generic
Dim input As New OcrInput()
input.LoadPdf("scanned.pdf")
' Cap orientation detection to 2 pages at a time. The default is one per CPU core.
Dim orientation As IEnumerable(Of OcrPageOrientationResult) =
input.DetectPageOrientation(OrientationDetectionMode.Fast, maxDegreeOfParallelism:=2)Imports IronOcr
Imports System.Collections.Generic
Dim input As New OcrInput()
input.LoadPdf("scanned.pdf")
' Cap orientation detection to 2 pages at a time. The default is one per CPU core.
Dim orientation As IEnumerable(Of OcrPageOrientationResult) =
input.DetectPageOrientation(OrientationDetectionMode.Fast, maxDegreeOfParallelism:=2)Environment.ProcessorCount로 돌아갑니다. 단일 인수 DetectPageOrientation 오버로드는 변경되지 않고 완전히 지원되므로 기존 코드는 수정 없이 계속 작동합니다.일반적인 성능 고려 사항은 무엇인가요?
성능은 모드 간에 크게 다릅니다. 빠른 모드는 고처리량 처리를 최적화하며, 극한 정밀은 속도를 희생하고 정확성을 우선시합니다. 정확도 요구 사항과 시간 제약에 따라 선택하세요. 최적의 성능을 위해:
- 이미지 해상도: 더 높은 DPI 설정은 정확성을 개선하지만 처리 시간을 증가시킵니다. 회전 감지에는 일반적으로 150-300 DPI가 충분합니다.
- 문서 유형: 텍스트가 빽빽한 문서는 드문 레이아웃보다 더 빠르고 정확하게 처리됩니다. 탐지 전에 이미지 품질을 최적화하려면 필터 마법사를 사용하세요.
- 자원 사용: 대량 배치 처리 시 메모리 사용을 모니터링하고 페이지가 동시에 분석되는 수를 제한하는
maxDegreeOfParallelism값을 전달하세요. 진행 추적을 구현하여 피드백을 제공하고 시스템 자원을 관리하세요. - 병렬 처리: 대규모 작업의 경우 IronOCR의 멀티스레딩을 사용하여 여러 문서를 동시에 처리하면서 정확성을 유지하세요. 메모리가 제한된 경우
MaxDegreeOfParallelism으로 제한하세요.
혼합 방향 문서를 어떻게 처리합니까?
혼합 방향 문서의 경우 DetectPageOrientation로 각각의 페이지를 개별적으로 처리한 다음 OCR 전에 페이지별 회전 수정을 적용하세요. 이렇게 하면 초기 상태와 관계없이 올바른 방향이 보장됩니다. 다음은 효과적인 접근 방식입니다:
// Process each page with individual rotation detection
for (int i = 0; i < results.Count; i++)
{
var pageResult = results[i];
// Apply rotation only to pages that need it
if (pageResult.RotationAngle != 0 && pageResult.HighConfidence)
{
// Load the specific page as its own input and correct it
using var pageInput = new OcrInput();
pageInput.LoadPdfPage("doc.pdf", i);
pageInput.Rotate(360 - pageResult.RotationAngle);
}
}// Process each page with individual rotation detection
for (int i = 0; i < results.Count; i++)
{
var pageResult = results[i];
// Apply rotation only to pages that need it
if (pageResult.RotationAngle != 0 && pageResult.HighConfidence)
{
// Load the specific page as its own input and correct it
using var pageInput = new OcrInput();
pageInput.LoadPdfPage("doc.pdf", i);
pageInput.Rotate(360 - pageResult.RotationAngle);
}
}' Process each page with individual rotation detection
For i As Integer = 0 To results.Count - 1
Dim pageResult = results(i)
' Apply rotation only to pages that need it
If pageResult.RotationAngle <> 0 AndAlso pageResult.HighConfidence Then
' Load the specific page as its own input and correct it
Using pageInput = New OcrInput()
pageInput.LoadPdfPage("doc.pdf", i)
pageInput.Rotate(360 - pageResult.RotationAngle)
End Using
End If
Next i' Process each page with individual rotation detection
For i As Integer = 0 To results.Count - 1
Dim pageResult = results(i)
' Apply rotation only to pages that need it
If pageResult.RotationAngle <> 0 AndAlso pageResult.HighConfidence Then
' Load the specific page as its own input and correct it
Using pageInput = New OcrInput()
pageInput.LoadPdfPage("doc.pdf", i)
pageInput.Rotate(360 - pageResult.RotationAngle)
End Using
End If
Next i품질이 다양한 스캔된 문서나 다중 페이지 TIFF와 관련된 복잡한 시나리오의 경우 최적의 결과를 위해 각 페이지를 개별적으로 전처리하세요.
혼합 형식 입력을 처리할 때, OcrResult 클래스는 상세한 페이지 정보를 제공하여 정교한 오류 처리 및 품질 관리 워크플로우를 가능하게 합니다. 대량 생산 환경의 경우 속도와 정확성의 균형을 맞추기 위해 빠른 OCR 구성 옵션을 탐색하세요.
텍스트와 바코드가 모두 포함된 문서를 처리할 때, IronOCR의 바코드 및 QR 읽기와 함께 OCR 기능을 사용하여 모든 정보를 한 번에 추출하여 효율성을 향상하세요.
자주 묻는 질문
IronOCR은 페이지 회전을 어떻게 감지하나요?
IronOCR은 DetectPageOrientation 메서드를 사용하여 PDF와 이미지의 페이지 회전 각도를 자동으로 식별하며, 0°, 90°, 180°, 270°의 방향을 감지하여 정확한 텍스트 추출을 보장합니다.
IronOCR에서 RotationAngle 속성의 목적은 무엇인가요?
IronOCR의 RotationAngle 속성은 각 페이지에 대해 감지된 회전 각도를 나타내는 데 사용됩니다. 이를 통해 개발자는 프로그래밍적으로 페이지의 방향을 수정하여 정확한 텍스트 렌더링과 추출을 가능하게 합니다.
IronOCR은 비표준 페이지 회전을 처리할 수 있나요?
네, 표준 0°, 90°, 180°, 270° 회전을 벗어난 비뚤어진 이미지에 대해 IronOCR은 이미지 보정 필터의 Deskew 메서드 사용을 제안하여 이미지를 적절히 정렬할 수 있습니다.
IronOCR에서 HighConfidence 속성은 무엇인가요?
IronOCR의 HighConfidence 속성은 감지된 방향의 신뢰도 수준을 반영합니다. 이는 더 많은 검증이 필요할 수 있는 모호한 문서나 저품질 스캔의 경우에 특히 유용합니다.
IronOCR은 감지 속도와 정확성을 어떻게 향상시킬 수 있나요?
IronOCR은 DetectPageOrientation을 위해 선택적인 OrientationDetectionMode 매개변수를 제공하여 사용자가 감지 속도와 정확성을 조정할 수 있으며, 사용자의 필요에 따라 Fast에서 ExtremeDetailed 모드까지 조정할 수 있습니다.
이 기능은 특정 유형의 문서에서 가장 효과적으로 작동합니까?
IronOCR의 페이지 방향 감지 기능은 텍스트 밀도가 높은 문서에서 최상의 성능을 발휘합니다. 텍스트가 적거나 레이아웃이 복잡한 문서의 경우, 최적의 결과를 얻으려면 감지 전에 이미지 품질 보정 필터를 적용하는 것이 좋습니다.
대용량 PDF에서 방향을 감지할 때 메모리 사용량을 어떻게 제한할 수 있나요?
DetectPageOrientation 오버로드에 maxDegreeOfParallelism 값을 전달하십시오. 예를 들어 input.DetectPageOrientation(OrientationDetectionMode.Fast, maxDegreeOfParallelism: 2). 이것은 동시에 분석되는 페이지 수를 제한하며, 각 동시 페이지는 자체 네이티브 엔진을 사용하기 때문에 피크 메모리를 직접 제한합니다. 비양수 값은 Environment.ProcessorCount로 되돌아갑니다.
maxDegreeOfParallelism 매개변수를 추가하면 기존 코드가 손상되나요?
아니요. 단일 인수 DetectPageOrientation 오버로드는 변경되지 않으며 완전히 지원되므로 기존 코드는 수정 없이 계속 작동합니다. Fast 모드에서는 방향 감지가 더 메모리 효율적이며, 이는 페이지마다 하나씩 할당하는 대신 작업자 스레드당 하나의 엔진을 재사용하기 때문이며, 결과는 변함이 없습니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.