Microsoft.ML.OnnxRuntime 在 CPU 上执行;运行时不需要下载模型,也不需要网络调用AsposeOcr.Recognize() 为核心,该方法接受一个OcrInput,该输入由一个或多个文件构建(InputType.SingleImage 或 InputType.PDF),并OcrOutput——每个图像或 PDF 页面对应一个 RecognitionResult,按源顺序排列。RecognitionResult 通过 RecognitionText 暴露完整的页面文本,RecognitionLinesResult 暴露各个识别行及其像素坐标的边界框。 PDF 页面在内部渲染(通过 Aspose.PDF.FOSS)` 在识别之前),dotnet add package Aspose.OCR.FOSS 安装。对于AsposeOcr.Recognize(OcrInput) 是同时处理图像和 PDF 的唯一入口点OcrInput 接受 InputType.SingleImage 或 InputType.PDF;添加一个或多个文件OcrInput.Add()InputType.PDF,每一页都会被识别并按源顺序返回OcrOutput —— 每个图像或 PDF 页对应一个 RecognitionResultRecognitionResult.RecognitionText 返回完整的识别页面文本RecognitionResult.RecognitionLinesResult 为每个检测到的文本行返回一个 RecognitionResult.LinesResult
每个检测到的文本行RecognitionResult.LinesResult.TextInLine 保存该行的识别文本RecognitionResult.LinesResult.Line 是一个 System.Drawing.Rectangle,提供该行在源图像中的像素坐标
在源图像中的像素坐标Microsoft.ML.OnnxRuntime 运行OcrInput 可以容纳多个文件;OcrOutput 保持它们的原始顺序InputType.SingleImage 和 InputType.PDF——任何其他输入类型都会抛出 NotSupportedException识别 PDF 的每一页并按源顺序打印每页的文本。
using Aspose.OCR;
var api = new AsposeOcr();
using var input = new OcrInput(InputType.PDF);
input.Add("document.pdf");
OcrOutput output = api.Recognize(input);
foreach (RecognitionResult page in output)
{
Console.WriteLine(page.RecognitionText);
}
识别单个光栅图像并打印其识别文本。
using Aspose.OCR;
var api = new AsposeOcr();
using var input = new OcrInput(InputType.SingleImage);
input.Add("scan.png");
RecognitionResult result = api.Recognize(input)[0];
Console.WriteLine(result.RecognitionText);
遍历识别的行并打印每行的文本以及其像素坐标。
using Aspose.OCR;
var api = new AsposeOcr();
using var input = new OcrInput(InputType.SingleImage);
input.Add("document.jpg");
RecognitionResult result = api.Recognize(input)[0];
foreach (RecognitionResult.LinesResult line in result.RecognitionLinesResult)
{
System.Drawing.Rectangle bounds = line.Line;
Console.WriteLine($"x={bounds.X}, y={bounds.Y}, width={bounds.Width}, height={bounds.Height}: {line.TextInLine}");
}
Aspose.OCR FOSS for .NET 是 MIT 许可证的。您可以使用、修改和重新分发它,包括在商业产品中,而无需额外的许可费用。
请参阅上面的安装章节以获取当前的安装命令。
拉丁文脚本文本。没有语言选择参数,嵌入式识别模型不支持非拉丁脚本。
不。所有三个 ONNX 模型(检测、细化、识别)都嵌入在程序集里,并通过 Microsoft.ML.OnnxRuntime 本地运行。
是的 — 在调用 AsposeOcr.Recognize() 之前,将多个文件添加到同一个 OcrInput 中。返回的 OcrOutput 会保留它们的顺序。