如何检测页面旋转
This article was translated from English: Does it need improvement?
TranslatedView the article in English
确定页面旋转涉及识别文档中页面应用的旋转度数。 此过程专门确定页面是顺时针还是逆时针旋转了0度、90度、180度和270度。 此信息对于准确渲染或处理文档至关重要,确保页面以正确的方向显示或打印。
IronOCR 将页面旋转检测提升到了一个新的水平。 一旦检测到旋转,返回的值可以与 Rotate
方法结合使用,以将图像调整到正确的方向。
开始使用IronOCR
立即在您的项目中开始使用IronOCR,并享受免费试用。
如何检测页面旋转
- 下载用于检测页面旋转的 C# 库
- 导入 PDF 文档和图像以供阅读
- 使用
检测页面方向
检测所有页面旋转的方法 - 访问 旋转角度 属性来纠正页面旋转
- 访问 高度自信 属性来处理边缘情况
检测页面旋转示例
在加载文档后,您可以使用 DetectPageOrientation
方法来识别每一页的旋转方向。 此方法支持 0、90、180 和 270 度。对于倾斜的图像,可以使用 Deskew
图像校正方法。 随后使用函数返回的角度将图像旋转回其原始方向。 让我们继续进行PDF 样本.
请注意
当文档文本密集时,该功能表现良好。
:path=/static-assets/ocr/content-code-examples/how-to/detect-page-rotation-detect-page-rotation.cs
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 result
VB C#
理解结果
- PageNumber:表示页面的从零开始的索引。
- RotationAngle:提供校正旋转角度,单位为度。 此角度可应用于
Rotate
方法以使图像恢复到正向旋转。 例如,如果图像顺时针旋转了90度,返回的角度将是270,然后可以将其传递给Rotate
方法作为input.Rotate
。(旋转角度)`. - HighConfidence:表示对方向结果的信心水平。