XY.OCR.UmiOCR 2.0.9

dotnet add package XY.OCR.UmiOCR --version 2.0.9
                    
NuGet\Install-Package XY.OCR.UmiOCR -Version 2.0.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XY.OCR.UmiOCR" Version="2.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XY.OCR.UmiOCR" Version="2.0.9" />
                    
Directory.Packages.props
<PackageReference Include="XY.OCR.UmiOCR" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add XY.OCR.UmiOCR --version 2.0.9
                    
#r "nuget: XY.OCR.UmiOCR, 2.0.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package XY.OCR.UmiOCR@2.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=XY.OCR.UmiOCR&version=2.0.9
                    
Install as a Cake Addin
#tool nuget:?package=XY.OCR.UmiOCR&version=2.0.9
                    
Install as a Cake Tool

XY.OCR.UmiOCR

基于 Umi-OCR HTTP API 的 OCR 文本提取类库,支持图片识别与 PDF 识别,开箱可用于 DI 注入。

发布Nuget 包

  • 包名称:XY.OCR.UmiOCR
  • 描述:基于 Umi-OCR HTTP API 的 OCR 文本提取类库,支持图片识别与 PDF 识别,开箱可用于 DI 注入。
  • PowerShell(pwsh)发布命令模板
cd F:\GitHub\XY.CO2NET;
dotnet pack .\XY.OCR.UmiOCR\XY.OCR.UmiOCR.csproj -c Release -o .\artifacts\nuget;
dotnet nuget push .\artifacts\nuget\XY.OCR.UmiOCR.*.nupkg --source https://api.nuget.org/v3/index.json --api-key "<YOUR_NUGET_API_KEY>" --skip-duplicate

安装与引用

将项目或 NuGet 包 XY.OCR.UmiOCR 引用到你的应用中。

Umi-OCR 下载与 HTTP 服务开启

1) 下载 Umi-OCR

2) 开启 HTTP API 服务

  • 在 Umi-OCR 客户端中进入 设置 / 接口 / HTTP API(不同版本菜单名称可能略有差异)。
  • 启用 HTTP 服务,并确认监听地址与端口(默认常见为 127.0.0.1:1224)。
  • 启用后可在本库配置中使用:
    • OcrUrl: http://127.0.0.1:1224/api/ocr
    • DocUrl: http://127.0.0.1:1224/api/doc

配置项

默认配置节:XYUmiOCR

{
  "XYUmiOCR": {
    "OcrUrl": "http://127.0.0.1:1224/api/ocr",
    "DocUrl": "http://127.0.0.1:1224/api/doc",
    "PollingIntervalMilliseconds": 1000,
    "MaxPollingAttempts": 300,
    "LineMergeThreshold": 10
  }
}

DI 注册方式

1) 从配置文件注册

services.AddXYUmiOCR(configuration);
// 或自定义配置节
services.AddXYUmiOCR(configuration, "OcrService");

2) 代码委托注册

services.AddXYUmiOCR(options =>
{
    options.OcrUrl = "http://127.0.0.1:1224/api/ocr";
    options.DocUrl = "http://127.0.0.1:1224/api/doc";
    options.PollingIntervalMilliseconds = 1000;
    options.MaxPollingAttempts = 300;
    options.LineMergeThreshold = 10d;
});

3) 直接参数注册

services.AddXYUmiOCR(
    ocrUrl: "http://127.0.0.1:1224/api/ocr",
    docUrl: "http://127.0.0.1:1224/api/doc",
    pollingIntervalMilliseconds: 1000,
    maxPollingAttempts: 300,
    lineMergeThreshold: 10d);

使用示例

public class OcrAppService
{
    private readonly IUmiOCRService _umiOcrService;

    public OcrAppService(IUmiOCRService umiOcrService)
    {
        _umiOcrService = umiOcrService;
    }

    public async Task<string> RecognizeImageAsync(byte[] imageBytes)
    {
        return await _umiOcrService.RecognizeImageAsync(imageBytes);
    }

    public async Task<string> RecognizePdfAsync(byte[] pdfBytes)
    {
        return await _umiOcrService.RecognizePdfAsync(pdfBytes, "sample.pdf", "application/pdf");
    }
}

接口说明

  • RecognizeImageAsync:发送图片到 Umi-OCR 图片接口,返回合并文本。
  • RecognizePdfAsync:上传 PDF、轮询任务、下载结果并合并文本,最后执行任务清理。

注意事项

  • 使用前请确认 Umi-OCR 服务可访问。
  • MaxPollingAttempts * PollingIntervalMilliseconds 决定 PDF 任务最长等待时间。
  • 若 Umi-OCR 返回格式与默认解析结构不一致,请按实际接口格式调整解析逻辑。
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.9 94 5/5/2026
2.0.8 100 4/27/2026
2.0.7 97 4/25/2026

[新增] Added
     - 增补 UmiOCR 图片/PDF 识别流程说明与 DI 配置说明。
     [优化] Improved
     - 统一 NuGet 元数据格式(Description/Tags/README/Icon/License/Repository)。
     [修复] Fixed
     - 修正发布说明与版本信息一致性,优化包检索呈现。