File: README.md

package info (click to toggle)
zxing-cpp 2.3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,832 kB
  • sloc: cpp: 32,803; ansic: 18,360; php: 1,156; python: 215; makefile: 25; sh: 3
file content (70 lines) | stat: -rw-r--r-- 2,276 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# zxing-cpp

zxing-cpp is a Rust wrapper for the C++ library [zxing-cpp](https://github.com/zxing-cpp/zxing-cpp).

It is an open-source, multi-format linear/matrix barcode image processing library implemented in C++.
It was originally ported from the Java ZXing Library but has been developed further and now includes
many improvements in terms of runtime and detection performance.

## Usage

In your Cargo.toml:

```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.1", features = ["bundled", "image"] }
```

Simple example reading some barcodes from a jpg file:

```rust
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(())
}
```

Simple example creating a barcode and writing it to a svg file:

```rust
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(())
}
```

Note: This should currently be considered a pre-release. The API may change slightly to be even more
idiomatic rust depending on community feedback.

## Optional Features

zxing-cpp provides features that are behind [Cargo features](https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section).
They are:

* `bundled` uses a bundled version of the [zxing-cpp](https://github.com/zxing-cpp/zxing-cpp) c++ library.
* [`image`](https://crates.io/crates/image) allows convenient/implicit conversion between `ImageView`/`Image` and`GreyImage`/`DynamicImage`.

## Benchmarking

To compare the performance of this Rust wrapper project with other available barcode scanner Rust libraries,
I started the project [zxing-bench](https://github.com/axxel/zxing-bench). The README contains a few
results to get an idea.