RapidOrientation 1.0.0

dotnet add package RapidOrientation --version 1.0.0
                    
NuGet\Install-Package RapidOrientation -Version 1.0.0
                    
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="RapidOrientation" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RapidOrientation" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RapidOrientation" />
                    
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 RapidOrientation --version 1.0.0
                    
#r "nuget: RapidOrientation, 1.0.0"
                    
#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 RapidOrientation@1.0.0
                    
#: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=RapidOrientation&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RapidOrientation&version=1.0.0
                    
Install as a Cake Tool

RapidOrientationCSharp

基于 ONNX Runtime 的文档方向分类库(C# 实现),是上游 rapid_orientation 的 .NET 移植版。 可打包到 NuGet 的 .NET 类库,并内置模型(作为嵌入式资源,无需额外下载)。

支持四方向分类:0 / 90 / 180 / 270 度。

安装

dotnet add package RapidOrientation

依赖:

  • Microsoft.ML.OnnxRuntime(推理引擎)
  • SixLabors.ImageSharp(图像解码与预处理)

用法

using RapidOrientation;

using var detector = new DocOrientationDetector();

// 返回旋转角度(0 / 90 / 180 / 270)
int degrees = detector.Detect(@"C:\path\to\image.jpg");

// 需要置信度与耗时信息时
OrientationResult result = detector.DetectWithResult(@"C:\path\to\image.jpg");
Console.WriteLine($"{result.Degrees} 度, 置信度 {result.Scores[result.Label]:P0}, 耗时 {result.ElapsedMilliseconds:F1} ms");

也支持从 byte[]Stream 输入:

byte[] bytes = File.ReadAllBytes(imagePath);
int degrees = detector.Detect(bytes);

using var stream = File.OpenRead(imagePath);
int degrees2 = detector.Detect(stream);

使用自定义模型

默认使用随包内置的模型。若需指定自己的 ONNX 模型:

using var detector = new DocOrientationDetector(@"C:\models\rapid_orientation.onnx");

模型输入要求:

输入 x,float32,[N, 3, 224, 224](BGR 通道顺序)
输出 fetch_name_0,float32,[N, 4](logits)
元数据 character:多行类别标签,如 0\n90\n180\n270

线程安全

DocOrientationDetector 的实例可安全地并发调用(ONNX Runtime Session 支持并发 Run)。

运行示例

dotnet run --project samples/RapidOrientation.Sample -- tests/RapidOrientation.Tests/TestFiles/img_rot180_demo.jpg

运行测试

dotnet test RapidOrientationCSharp.slnx

构建并打包 NuGet

dotnet pack src/RapidOrientation/RapidOrientation.csproj -c Release

产物位于 src/RapidOrientation/bin/Release/RapidOrientation.<version>.nupkg,可推送到 nuget.org:

dotnet nuget push src/RapidOrientation/bin/Release/RapidOrientation.1.0.0.nupkg --api-key <key> --source https://api.nuget.org/v3/index.json

说明

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 was computed.  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. 
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
1.0.0 117 8/1/2026