VisionAnnotation 1.0.4

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

VisionAnnotation(视觉标注库)

视觉标注显示专用库,独立维护、独立打包(NuGet: VisionAnnotation)。 主程序(视觉流程图)只调用本库做结果显示,不自带标注布局代码。

包含内容

目录 内容
Detection/ Detection(一个检测/标注对象)、LabelLayout(文字框自动避让布局)、BusyMap(图像空白度栅格)、DetectionRenderer / DetectionStyle(框+引线+文字的绘制与样式)
Controls/ VisionViewer(交互控件:缩放/平移/状态条)、VisionRenderer(离屏渲染出位图)
Annotation/ 手工箭头/尺寸线标注(LineAnnotation 等)

数据契约(铁律):数值是数值,名称是名称

  • Detection.Value(double?)= 数值,Detection.ValueFormat / UnitText 控制显示格式;
  • Detection.Name(string)= 名称,可能被翻译/改名,渲染层经 DetectionStyle.TextLocalizer 钩子过一遍再显示(多语言在这里接入);
  • 显示文本由渲染层组合(Detection.DisplayText):有 Name/Value 按结构化组合, 都没有才回退 CustomText 原文。新代码禁止把名称和数值拼成一个字符串塞进来。

快速上手(脱离视觉流程图单独调用)

装包:dotnet add package VisionAnnotation(或引用本地 nupkg)。 命名空间 VisionAnnotation,只依赖 System.Drawing,WinForms / 控制台 / 离线出图都能用。

场景一:WinForms 窗口里交互显示(VisionViewer)

var viewer = new VisionViewer { Dock = DockStyle.Fill };
form.Controls.Add(viewer);

viewer.Image = Image.FromFile(@"D:\IMG\part.png");   // 底图
viewer.Detections = new List<Detection>
{
    new Detection
    {
        X1 = 100, Y1 = 80, X2 = 260, Y2 = 200,   // 框(图像像素坐标)
        Name = "左孔",                            // 名称(可多语言)
        Value = 12.345, UnitText = "mm",          // 数值 + 单位
        LabelAnchorX = 180, LabelAnchorY = 140,   // 引线指向的锚点(可选)
        LabelColor = Color.LimeGreen              // 单独配色(可选)
    }
};
viewer.ZoomToFit();

缩放 / 平移 / 状态条控件自带;DetectionStyle 属性可在 PropertyGrid 里直接编辑 (引线、字号、类别配色、文字背景等)。

场景二:无窗口离屏出图(VisionRenderer,适合批量导出 / 存证)

using var img = Image.FromFile(@"D:\IMG\part.png");
var style = new DetectionStyle { PreferLocalLabels = true };
using var busy = BusyMap.Build(img);              // 文字自动挑空白背景(可选,传 null 跳过)
using var bmp = VisionRenderer.Render(
    new Size(1280, 960), img, detections, style,
    annotation: null, busyMap: busy, dpi: 1f,
    backColor: Color.FromArgb(30, 30, 30), caption: "OK");
bmp.Save(@"D:\存证\result.png");

场景三:画到自己已有的 Graphics 上(DetectionRenderer)

// imageRect = 图片在你画布上的显示矩形;imageSize = 图片像素尺寸
DetectionRenderer.Draw(g, imageRect, clientRect, image.Size,
    detections, style, busyMap: null, dpi: 1f,
    extraObstacles: myMeasureRects);   // 已画的测量图形包围盒,文字只避让不重复画

多语言 / 改名

style.TextLocalizer = name => name switch
{
    "左孔" => "Left Hole",
    "边3"  => "Edge 3",
    _ => name
};

只翻译 Name;Value / ValueFormat / UnitText 不受影响(数值是数值、名称是名称)。

常用成员速查

需求 成员
文字避让更"贴目标"(就近分散) DetectionStyle.PreferLocalLabels = true
只要文字不要框 DetectionStyle.ShowBoxes = false
只当障碍物不画文字 Detection.IsObstacleOnly = true
引线指向精确测量点而非框边 Detection.LabelAnchorX/Y
引线终点限制在某框内 Detection.LeaderBounds
控件截图(带标注) VisionViewer.RenderView() / RenderToBitmap(size)

启用 ONNX 推理(默认关闭)

标注显示本体零第三方依赖。ONNX 推理扩展默认不编译:

  1. 删除 csproj 里 ItemGroup 的两行 Compile Remove;
  2. dotnet add package Microsoft.ML.OnnxRuntime;
  3. VisionViewer 即多出 ModelPath / LoadModel / DetectAsync / AutoDetect 等成员。

打包

pack-视觉标注.cmd

产物在 bin\Release\VisionAnnotation.1.0.0.nupkg。

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows 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.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on VisionAnnotation:

Package Downloads
VisionFlow

视觉流程图框架:流程图引擎([FlowNode] 节点注册、JSON 序列化、拓扑执行、配方)+ WinForms 编辑器控件 + csx 脚本 / .cs 源码 / DLL 算子包四种扩展载体。内置视觉算子(旋转模板匹配/综合测量/OCR/读码/颜色抽取/深度学习目标检测)随包自动部署,装一个包即可用。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 206 11/2/2026
1.0.1 107 11/2/2026
1.0.0 112 10/31/2026