CvSharp.Barcode 1.0.0

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

CvSharp.Barcode

.NET 平台上识别率全面超越 ZXing-C++ 的条码识别库。

移植 ZXing-C++ 全部五种码制解码核心,换掉它已显老态的图像前端,换上 CvSharp 现代视觉算子, 再加三项 ZXing-C++ 根本没有的能力。在 MVTec HALCON 工业标准测试图集上实测: ZXing-C++ 能解的我们全解,ZXing-C++ 解不出的 25 张我们解出,反向差距为零。

硬数据:与 ZXing-C++ 逐项对比

测试集:MVTec HALCON-10.0 标准工业条码图集 + 自生成退化样本集(旋转/噪声/模糊/低对比度/透视/反色), 同一批图、同一台机器、双侧均开最大努力模式。

测试集 双方一致 仅 CvSharp.Barcode 解出 仅 ZXing-C++ 解出
一维码(9 种码制全集) 48 13 0
DataMatrix ECC200(78 张) 19 5 0
PDF417(HALCON 26 张) 5 7 0
QR 合成退化集 命中 100% — ZXing 95%
PDF417 合成集(37 张) 37/37 双方全中 — —
Aztec 合成集(29 张) 28/29 — ZXing 26/29(2 张为其绑定层转义差异)

五个码制,没有一个图是 ZXing-C++ 能解而我们解不出的。

三项 ZXing-C++ 没有的能力

1. 任意角度旋转一维码 ZXing-C++ 只能扫水平和垂直方向的一维码,斜置 30° 就瞎。 CvSharp.Barcode 沿 ±15°~±75° 任意角度做双线性扫掠采样,斜着、歪着、贴在曲面上的码照解。

2. 维纳反卷积去模糊重试 离焦、运动模糊导致全部码制识别失败时,自动对图像做维纳反卷积增强后重试。 HALCON ecc200_to_preprocess、ean13_to_preprocess 这批双方全败的样本,就是这样被救回来的。 这是现代反卷积算法对 ZXing 时代预处理思路的代差碾压。

3. 单门面全码制 + 多角度多策略流水线 一个 BarcodeReader 通吃 13 种码制,直方图双峰取谷行扫描、分块黑点估计二值化(HybridThreshold)、 灰度重采样回退、反色重试、斜扫重试、去模糊重试按最优顺序自动接力。 你只需要 Decode(img),剩下的它自己想办法。

支持的码制

类别 码制
二维码 QR Code、DataMatrix (ECC200)、PDF417、Aztec(含 Rune)
一维码 EAN-13、EAN-8、UPC-A、UPC-E、Code 39、Code 93、Code 128、Codabar、ITF

30 秒上手

using CvSharp;
using CvSharp.Barcode;

using Mat img = Cv.ImRead("barcode.png", ImreadMode.Grayscale);

var reader = new BarcodeReader();
BarcodeResult? r = reader.Decode(img);
Console.WriteLine($"[{r.Format}] {r.Text}");

// 一张图里有多少解多少
foreach (var b in reader.DecodeMulti(img))
    Console.WriteLine($"{b.Format}: {b.Text}");

失败返回 null / 空数组,永不抛异常——生产线级的健壮性约定: 单个码制的解析异常被隔离吞没,绝不会因为一个坏图崩掉你的识别进程。

性能调优选项

属性 默认 说明
Formats All 限定码制是最有效的提速手段
TryHarder 开 关闭约提速一倍,识别率略降
TryMultiAngle 开 任意角度斜扫;只扫正置码可关
TryDeblur 开 去模糊重试,仅在完全失败路径触发,成功图零开销
TryInverted / TryRotate / TryPure / TryGrayResampling 开 各条增强通道,均可独立关闭
Binarizers All Otsu / Hybrid / AdaptiveGaussian / DynThreshold 按需裁剪
MaxSymbols 16 多码返回上限

典型耗时(600×600 工业图,含全部增强通道):一维码约 100ms,QR 约 200ms; 关闭增强通道后可达 ZXing-C++ 同级速度,识别率仍然更高——速度和识别率,你任选。

目标框架

  • .NET 8
  • .NET Framework 4.6.1(老产线、老工控机直接可用,编码走框架内置实现)

.NET Framework 项目引用时请设置 RuntimeIdentifier(如 win-x64), 以便 CvSharp 原生库随输出部署。

许可

Apache-2.0。部分解码核心移植自 ZXing / ZXing-C++(Apache-2.0),图像前端与增强流水线为原创实现。

GreatBear 出品。

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. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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.2.9 151 10/19/2026
1.2.4 112 10/18/2026
1.0.0 113 10/18/2026