Leaf.CvLibrary
1.0.8
dotnet add package Leaf.CvLibrary --version 1.0.8
NuGet\Install-Package Leaf.CvLibrary -Version 1.0.8
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="Leaf.CvLibrary" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Leaf.CvLibrary" Version="1.0.8" />
<PackageReference Include="Leaf.CvLibrary" />
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 Leaf.CvLibrary --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Leaf.CvLibrary, 1.0.8"
#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 Leaf.CvLibrary@1.0.8
#: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=Leaf.CvLibrary&version=1.0.8
#tool nuget:?package=Leaf.CvLibrary&version=1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Leaf.CvLibrary
基于 OpenCvSharp 封装的图像处理与计算机视觉库,提供简洁易用的 API 和强大的图像处理功能。
📦 安装
通过 NuGet 包管理器安装
dotnet add package Leaf.CvLibrary
或在 Visual Studio 中使用包管理器控制台:
Install-Package Leaf.CvLibrary
手动安装依赖
dotnet add package Leaf.CvCommon
dotnet add package OpenCvSharp4.Windows
🎯 功能特性
图像预处理
- 平滑处理 - 高斯模糊降噪
- 阈值分割 - 二值化图像分割
- 连通组件分析 - 区域检测与标记
图像匹配
- 模板匹配
- 特征点匹配
图像对齐
- 基于特征点的图像对齐
- 仿射变换对齐
图像测量
- 区域面积、周长计算
- 质心位置计算
- 边界框提取
图像绘制
- 绘制点、线、矩形、圆形
- 叠加文本和标记
通用工具
- 灰度值统计(最小值、最大值)
- 最大区域选择
- 像素格式转换
🚀 快速开始
示例 1:图像平滑与阈值分割
using CvLibrary.OpenCV;
using OpenCvSharp;
// 加载图像
var image = Cv2.ImRead("input.jpg", ImreadModes.Grayscale);
// 平滑处理
var smoothed = CvTool.Smooth(image, ksize: 5);
// 阈值分割
var region = CvTool.Threshold(smoothed, threshold: 128);
// 保存结果
region.Mask.SaveImage("output.jpg");
示例 2:连通组件分析
using CvLibrary.OpenCV;
using OpenCvSharp;
// 加载二值化图像
var image = Cv2.ImRead("binary.jpg", ImreadModes.Grayscale);
var region = new CvRegion(image);
// 连通组件分析
var components = CvTool.ConnectionComponents(region);
// 选择最大区域
var maxRegion = CvTool.SelecteMaxAreaRegion(components);
Console.WriteLine($"最大区域面积: {maxRegion.RegionProperties.Area}");
Console.WriteLine($"质心位置: ({maxRegion.RegionProperties.Centroid.X}, {maxRegion.RegionProperties.Centroid.Y})");
示例 3:灰度值统计
using CvLibrary.OpenCV;
using OpenCvSharp;
var image = Cv2.ImRead("image.jpg", ImreadModes.Grayscale);
// 获取最小和最大灰度值
var (minValue, maxValue) = CvTool.GetMinMaxGrayValue(image);
Console.WriteLine($"最小灰度值: {minValue}");
Console.WriteLine($"最大灰度值: {maxValue}");
🏗️ 项目结构
Leaf.CvLibrary/
├── src/
│ ├── CvCommon/ # 通用基础元素库
│ ├── CvLibrary/ # 核心图像处理库
│ │ └── OpenCV/
│ │ ├── CvRegion.cs # 区域定义
│ │ ├── CvRegionProperties.cs # 区域属性
│ │ ├── CvTool.Common.cs # 通用工具
│ │ ├── CvTool.PreProcess.cs # 预处理工具
│ │ ├── CvTool.Match.cs # 匹配工具
│ │ ├── CvTool.Alignment.cs # 对齐工具
│ │ ├── CvTool.Measure.cs # 测量工具
│ │ ├── CvTool.Draw.cs # 绘制工具
│ │ └── CvTool.Image.cs # 图像工具
│ └── CvLibraryExtensions/ # 扩展功能库
├── README.md
├── LICENSE
└── THIRD-PARTY-NOTICES.txt
📋 系统要求
- .NET 8.0 或更高版本
- 支持平台:
- Windows (x64, AnyCPU)
- Linux (需要 OpenCvSharp4.runtime.linux)
- macOS (需要 OpenCvSharp4.runtime.osx)
🔧 依赖项
- Leaf.CvCommon (>= 1.0.2) - 基础数据结构
- OpenCvSharp4.Windows (>= 4.11.0) - OpenCV 包装库
📚 API 文档
CvTool 类
| 方法 | 描述 |
|---|---|
Smooth(Mat, int) |
高斯模糊平滑 |
Threshold(Mat, double, double) |
阈值二值化 |
ConnectionComponents(CvRegion) |
连通组件分析 |
GetMinMaxGrayValue(Mat) |
获取灰度值范围 |
SelecteMaxAreaRegion(CvRegion) |
选择最大区域 |
CvRegion 类
表示图像中的一个区域,包含掩码和区域属性。
CvRegionProperties 类
包含区域的统计属性:
Area- 面积Centroid- 质心BoundingBox- 边界框Label- 标签
🤝 贡献
欢迎提交 Issue 和 Pull Request!
- Fork 本仓库
- 创建您的特性分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开一个 Pull Request
📝 版本历史
v1.0.4 (最新版本)
- 当前稳定版本
v1.0.3
- 改进性能和稳定性
v1.0.2
- 新增功能和 Bug 修复
👤 作者
Mitsuha9527
- GitHub: @Mitsuha9527
- 项目主页: Leaf.CvLibrary
📄 许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
本项目使用了以下第三方库:
- OpenCvSharp - Apache License 2.0(详见 THIRD-PARTY-NOTICES.txt)
🔗 相关链接
⭐ 支持
如果这个项目对您有帮助,请给它一个星标 ⭐!
Made with ❤️ by Mitsuha9527
| Product | Versions 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.
-
net8.0
- Leaf.CvCommon (>= 1.0.5)
- OpenCvSharp4.Windows (>= 4.11.0.20250507)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Leaf.CvLibrary:
| Package | Downloads |
|---|---|
|
Leaf.CvLibraryExtensions
CvLibrary的扩展功能库 |
|
|
Leaf.ML
基于ML.Net的图像分类深度学习库 |
|
|
Leaf.OCR
基于OpenVino和PPOCR的OCR识别库 |
|
|
Leaf.YOLO
基于ONNX Runtime与OpenVINO执行提供器的YOLO目标检测库 |
GitHub repositories
This package is not used by any popular GitHub repositories.