4 个版本 (重大更新)

0.4.0 2024年3月13日
0.3.0 2024年2月18日
0.2.2 2024年1月30日
0.1.0 2024年1月21日

#194图像

Download history 146/week @ 2024-03-13 10/week @ 2024-03-20 7/week @ 2024-03-27 16/week @ 2024-04-03 11/week @ 2024-04-24 90/week @ 2024-05-01 3/week @ 2024-06-19 85/week @ 2024-06-26

每月88次 下载

Apache-2.0

1.5MB
36K SLoC

C 21K SLoC // 0.1% comments C++ 14K SLoC // 0.1% comments Rust 819 SLoC // 0.0% comments

zxing-cpp

zxing-cpp 是 C++ 库 zxing-cpp 的 Rust 包装器。

它是一个开源的多格式线性/矩阵条码图像处理库,用 C++ 实现。最初是从 Java ZXing 库移植过来,但经过进一步开发,现在在运行时和检测性能方面包含了许多改进。

用法

在您的 Cargo.toml 中

[dependencies]
# `bundled` causes cargo to compile and statically link an up to
# date version of the c++ core library. This is the most convenient
# and safe way to build the library.
zxing-cpp = { version = "0.4.0", features = ["bundled", "image"] }

简单示例:从 jpg 文件中读取一些条码

use zxingcpp::BarcodeFormat;

fn main() -> anyhow::Result<()> {
	let image = image::open("some-image-file.jpg")?;

	let read_barcodes = zxingcpp::read()
		.formats(BarcodeFormat::QRCode | BarcodeFormat::LinearCodes)
		.try_invert(false);

	let barcodes = read_barcodes.from(&image)?;

	for barcode in barcodes {
		println!("{}: {}", barcode.format(), barcode.text());
	}

	Ok(())
}

简单示例:创建条码并将其写入 svg 文件

fn main() -> anyhow::Result<()> {
	let svg = zxingcpp::create(zxingcpp::BarcodeFormat::QRCode)
		.from_str("https://github.com/zxing-cpp/zxing-cpp")?
		.to_svg_with(&zxingcpp::write().scale(5))?;
	std::fs::write("zxingcpp.svg", svg)?;
	Ok(())
}

注意:这目前应被视为预发布版。API 可能会根据社区反馈进行轻微调整以更加“rusty”。

可选功能

zxing-cpp 提供的功能位于 Cargo 功能 之下。它们是

  • bundled 使用 zxing-cpp C++ 库的捆绑版本。
  • image 允许从 GreyImageDynamicImage 创建方便的/隐式的 ImageView

基准测试

为了比较这个 Rust 包装器项目与其他可用的条码扫描 Rust 库的性能,我开始了一个项目 zxing-bench。README 中包含了一些结果以获得一些想法。

依赖关系

~0.4–4.5MB
~43K SLoC