Skip to content

axxel/zxing-cpp

 
 

Repository files navigation

Build Status

ZXing-C++

ZXing-C++ ("zebra crossing") 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. It can both read and write barcodes in a number of formats. Since version 3.0 the default writing backend is provided by the zint library.

Sponsors

You can sponsor this library at GitHub Sponsors.

Named Sponsors:

Thanks a lot for your contribution!

Features

Supported Formats

Linear product Linear industrial Matrix
UPC-A Code 39 QR Code
UPC-E Code 93 Micro QR Code
EAN-8 Code 128 rMQR Code
EAN-13 Codabar Aztec
DataBar DataBar Expanded DataMatrix
DataBar Limited DX Film Edge PDF417
ITF MaxiCode (partial)

[Note:]

  • DataBar used to be called RSS.
  • DataBar, DX Film Edge, MaxiCode, Micro QR Code and rMQR Code are not supported for writing (unless the library is configured ZXING_WRITERS=NEW).

Getting Started

To read barcodes:

  1. Load your image into memory (3rd-party library required).
  2. Call ReadBarcodes() from ReadBarcode.h, the simplest API to get a list of Barcode objects.

A very simple example looks like this:

#include "ZXing/ZXingCpp.h"
#include <iostream>

int main(int argc, char** argv)
{
    int width, height;
    unsigned char* data;
    // load your image data from somewhere. ImageFormat::Lum assumes grey scale image data.

    auto image = ZXing::ImageView(data, width, height, ZXing::ImageFormat::Lum);
    auto options = ZXing::ReaderOptions().formats(ZXing::BarcodeFormat::Any);
    auto barcodes = ZXing::ReadBarcodes(image, options);

    for (const auto& b : barcodes)
        std::cout << ZXing::ToString(b.format()) << ": " << b.text() << "\n";

    return 0;
}

To see the full capability of the API, have a look at ZXingReader.cpp.

[Note: At least C++17 is required on the client side to use the API.]

To write barcodes:

  1. Create a Barcode object with CreateBarcode() from CreateBarcode.h.
  2. The Barcode::symbol() can be used to get access to the bit matrix (1 module == 1 pixel, no quiet zone)
  3. Alternatively the 3 WriteBarcodeTo...() functions from WriteBarcode.h can be used to create an Image, a SVG string or a UTF-8 string representation.

A very simple example looks like this:

#include "ZXing/ZXingCpp.h"
#include <iostream>

int main(int argc, char** argv)
{
    auto barcode = ZXing::CreateBarcodeFromText("some text", ZXing::BarcodeFormat::QRCode);
    auto svg = ZXing::WriteBarcodeToSVG(barcode);

    // see also ZXing::WriteBarcodeToImage()

    std::cout << svg << "\n";

    return 0;
}

As an example for how to parameterize the process with CreatorOptions and WriterOptions, have a look at ZXingWriter.cpp.

Web Demos

[Note: those live demos are not necessarily fully up-to-date at all times.]

Build Instructions

These are the generic instructions to build the library on Windows/macOS/Linux. For details on how to build the individual wrappers, follow the links above.

  1. Make sure CMake version 3.16 or newer is installed. The python module requires 3.18 or higher.
  2. Make sure a sufficiently C++20 compliant compiler is installed (minimum VS 2019 16.10? / gcc 11 / clang 12?).
  3. See the cmake ZXING_... options to enable the testing code, python wrapper, etc.
git clone https://github.com/zxing-cpp/zxing-cpp.git --recursive --single-branch --depth 1
cmake -S zxing-cpp -B zxing-cpp.release -DCMAKE_BUILD_TYPE=Release
cmake --build zxing-cpp.release -j8 --config Release

[Note: binary packages are available for/as vcpkg, conan, mingw and a bunch of linux distributions.]

About

C++ port of ZXing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 52.5%
  • C 39.9%
  • CMake 1.5%
  • Kotlin 1.2%
  • Rust 1.2%
  • Objective-C++ 0.9%
  • Other 2.8%