ZBar: Document AI - Efficient extraction of barcodes

Mohamed Dhiab

In the world of document processing and data management, the ability to decode barcodes quickly and accurately plays a critical role. Barcodes are ubiquitous in a variety of industries, from retail and logistics to the public health and manufacturing, and serve as indispensable tools for tracking, identification, and inventory management. Using advanced technologies like ZBar for barcode decoding in Document AI can significantly streamline workflows and increase overall efficiency. In this blog post, we explain this library, its benefits, and how it can revolutionize barcode decoding in Document AI.

This article was written in German, automatically translated into other languages and editorially reviewed. We welcome feedback at the end of the article.


What is zbar? ZBar is an open-source software package for reading barcodes from various sources, including images, videos and PDF documents. It supports various types of barcodes, such as QR codes, EAN-13, Code 128 and many others. The library offers a user-friendly interface, making it a popular choice for developers and businesses looking to integrate barcode scanning capabilities into their applications and workflows.

The role of ZBar in Document AI

Document AI, an evolving field of artificial intelligence, focuses on automating document processing tasks to reduce human intervention and speed data extraction. By integrating ZBar with Document AI solutions, organizations can efficiently capture barcode data from large volumes of documents such as invoices, shipping labels, and inventory records. This integration increases the accuracy of data extraction and minimizes the risk of human error, resulting in improved operational efficiency.

ZBar advantages

  • Speed and efficiency:

    The optimized algorithms of this library enable fast decoding of barcodes in real time. This makes them ideal for processing large document volumes. By automating barcode scanning, Document AI applications based on ZBar can significantly reduce processing time. This allows companies to focus on higher value tasks.
  • Accuracy and reliability:

    The accuracy of barcode decoding is critical. This is especially true for industries where accurate identification is essential for logistics, product tracking, and regulatory compliance. Robust decoding capabilities ensure reliable results. They also minimize the likelihood of bar codes being misread or overlooked. The result is improved data integrity.
  • Cross-platform compatibility

    The library is designed to work on multiple platforms and in multiple programming languages. This makes it highly adaptable to different applications. ZBar fits seamlessly into the existing technology stack and simplifies the development process.

Implementation with Python: A Step-by-Step Guide

1. start the installation of pyzbar

pip install pyzbar

2. load image or document with cv2 (you can also use Pillow or another package).

import cv2
image_path = "path/to/your/image.png"
image = cv2.imread(image_path)

3. barcode scanning, use now pyzbarto scan the image for barcodes and extract the decoded data.

from pyzbar.pyzbar import decode
decoded_barcodes = decode(image)

4. loop through the decoded barcodes. After that, each result is superimposed on the original image in the form of a rectangle. Don't forget to use the barcode data as a label for this rectangle.

for barcode in barcodes:
    barcode_data = barcode.data.decode("utf-8")
    x, y, w, h = barcode.rect
    cv2.rectangle(image, (x, y), (x+w, y+h), (255,0,255), 2)
    cv2.putText(image, barcode_data, (x, y - 10),
                1, (255,0,255), 2)


Here is an example of how the result of processing a document with barcodes on Konfuzio would look like:

If you want to use our barcode decoding solution, please feel free to contact us via the contact form.

Alternatives to ZBar


ZXing-C++ ("Zebra crossing") is an in C++ implemented open source library for processing linear/matrix barcodes in multiple formats.

It was originally ported from the Java ZXing Library, but has been further developed and now includes many improvements in quality and performance. It can both read and write barcodes in a number of formats.

The library has been carefully prepared in pure C++17 (/C++20) developed. This ensures a solid foundation without relying on third-party dependencies. In particular, it offers thread safety and has an impressive selection of wrappers/bindings for various platforms. For example: Android, C, iOS, Python, WebAssembly, WinRT and even Flutter.


QuaggaJS is a barcode scanner written entirely in JavaScript. It supports real-time localization and decoding of various barcode types. For example: EAN, CODE 128, CODE 39, EAN 8, UPC-A, UPC-C, I2of5, 2of5, CODE 93 and CODABAR.

The library can directly access the user's camera stream. Although the code is based on complex image processing, smartphones are able to locate and decode barcodes in real time.


If you've enjoyed Konfuzio's AI blogs so far, we've got a treat for you! Explore our extensive collection of captivating articles that delve into the fascinating world of Document AI:

    🐍✨Looking for a new challenge?

    Join the AI Comedy Club! Immerse yourself in a world where AI and humor meet and use this stage to showcase your skills. Whether you're an aspiring youngster or an experienced developer, here's your chance to show off your Python skills in a fun and innovative way. Also discover opportunities to contribute and even apply for a job with us.

    Ready to code, laugh and impress?

    Take a look at our AI Comedy Club Challenge and find out where your humor and Python skills can take you!

    Apply for data scientist, backend developer, data engineer, software developer, python software developer jobs.

    About me

    More Articles

    what is a bot title

    What is a bot? Definition, applications and types

    Bots are ubiquitous in today's digital world and have already had a significant impact on the way...

    Read article
    Charlotte Goetz

    Hello, I am Charlotte Götz 😊

    The passion for writing for many years was the deciding factor to follow the notorious path "from hobby to profession". I am...

    Read article
    data analytics title

    How data analytics leads companies to better results

    Data analytics are rapidly changing the way businesses operate in today's data-driven world. In the process, companies are leveraging advanced...

    Read article