# How to Benchmark Barcode Reading in Python with ZXing-C++ and Dynamsoft Barcode Reader

Canonical: https://www.dynamsoft.com/codepool/benchmark-barcode-reading-python-zxing-dynamsoft-barcode-reader.html
Markdown: https://www.dynamsoft.com/codepool/benchmark-barcode-reading-python-zxing-dynamsoft-barcode-reader.md
Description: Build an auditable Python benchmark for the zxing-cpp 3.1.1 wheel and Dynamsoft Capture Vision 3.6.5000 on 8,000 synthetic images, with a direct comparison to the C++ and JavaScript runs.
Author: Xiao Ling
Published: 2026-07-30
Updated: 2026-11-30
Topics: Dynamsoft Barcode Reader, ZXing-C++, Python, barcode benchmark

Two pip-installable readers can see the exact same pixels and still disagree on most of a difficult corpus. This benchmark scores the open-source [ZXing-C++ Python package](https://pypi.org/project/zxing-cpp/) (zxing-cpp 3.1.1) and [Dynamsoft Barcode Reader](https://www.dynamsoft.com/barcode-reader/docs/server/programming/python/) (Capture Vision 3.6.5000, DBR 11.6.50.1028) over 8,000 synthetic JPEGs from the [Dynamsoft synthetic barcode corpus](https://github.com/Dynamsoft/datasets-from-dynamsoft/tree/main/synthetic-benchmark) — 11,372 annotated symbols across 24 symbologies, 36 reusable background scenes, and 200 background-only controls.

Every image is loaded once with OpenCV and handed to every reader as the same ndarray, and every decode result ships with the project. Because the [C++](https://www.dynamsoft.com/codepool/benchmark-barcode-reading-cpp-zxing-dynamsoft-barcode-reader.html) and [JavaScript](https://www.dynamsoft.com/codepool/benchmark-barcode-reading-javascript-zxing-wasm-dynamsoft-barcode-reader.html) companions score the identical verified manifest, the series reads as one controlled experiment: unchanged input, one set of matching rules, a different language binding. On this run, Dynamsoft Barcode Reader returned 6,701 exact images (83.76%) against 3,852 (48.15%) for the ZXing-C++ wheel. The [three-reader Python comparison](https://www.dynamsoft.com/codepool/python-zxing-zbar-barcode.html) adds PyZBar to the same run.

![ZXing-C++ and Dynamsoft Barcode Reader Python synthetic benchmark](https://www.dynamsoft.com/codepool/img/2026/07/barcode-benchmark-python-zxing-dynamsoft.png)

**What you'll build:** A script-driven Python benchmark that verifies the synthetic manifest, times `zxingcpp` and `CaptureVisionRouter` on identical images, validates the raw records, and ships both the JSONL stream and a self-contained HTML report for review.


## Key Takeaways

- The corpus holds 8,000 JPEGs, 11,372 annotated symbols, 24 symbologies, and 36 background scenes, including 200 controls where an empty response is correct.
- Each file is loaded once with OpenCV and handed to every reader as the same image object. Only the decoder call is timed, so loading, matching, serialization, and reporting stay outside the clock.
- A correct image needs a one-to-one match for every expected format and payload with no extra predictions. SDK errors count as no read, and every unmatched prediction lowers precision.
- On one full pass with `ReadBarcodes_Default` and `BF_ALL`, DBR reached **6,701 / 8,000 exact images (83.76%)** and **9,662 / 11,372 matched symbols (84.96% recall)**, against **3,852 exact images (48.15%)** and **5,616 matched symbols (49.38%)** for ZXing-C++.
- The ZXing-C++ wheel is faster (14.12 ms mean versus 51.88 ms) but cannot decode 3,840 annotated symbols in postal, DotCode, MSI, and Pharmacode formats.

## Common Developer Questions

### How do I benchmark ZXing-C++ against Dynamsoft Barcode Reader fairly in Python?

Keep the input, the format policy, and the scoring identical for both sides. The harness loads each file once with OpenCV, hands the same ndarray to `zxingcpp.read_barcodes()` and `CaptureVisionRouter.capture()`, enables every supported format without per-image hints, times only the decode call, and grades both output streams with one location-independent matcher. The manifest SHA-256 and the raw results SHA-256 are recorded in `run.json` so any post-run edit is visible.

### Which barcode reader performed better on the synthetic corpus in Python?

Dynamsoft Barcode Reader led on image accuracy and symbol coverage: **6,701 of 8,000 exact images (83.76%)** versus **3,852 (48.15%)**, and **9,662 of 11,372 symbols (84.96% recall)** versus **5,616 (49.38%)**. On the 11 symbologies all three Python readers support, DBR reached 94.26% recall against 76.39% for ZXing-C++ and 76.89% for PyZBar over 5,175 annotated symbols. Precision is 98.88% for DBR, 98.93% for ZXing-C++ and 95.60% for PyZBar, and none of the three readers returned a prediction on the background-only controls.

### When should I choose Dynamsoft Barcode Reader instead of ZXing-C++ for a Python project?

Prefer Dynamsoft Barcode Reader when the cost of a missed scan outweighs the decode budget — difficult images, mixed symbologies, postal codes, or production workflows that need packaged templates and commercial support. Prefer `zxing-cpp` when you want an open-source baseline with inspectable source, no licensing fees, a lower per-call latency, and barcode input restricted to its 16 supported formats.

### Do the Python results match the C++ and JavaScript benchmarks on the same images?

Broadly yes, with runtime-driven deltas. On the same 8,000 images, DBR scored 83.76% exact images in Python, 83.93% in native C++, and 81.20% in the browser; the ZXing-C++ core scored 48.15%, 48.15%, and 48.14%. Decode times are not directly comparable because the three runs use different operating systems, image paths, and SDK packaging; the comparison table below isolates the accuracy side.

## Full Synthetic Benchmark Video

The recording walks through the corpus, the shared input path, and the final accuracy and timing numbers.

<video src="https://www.dynamsoft.com/codepool/img/2026/07/barcode-benchmark-python-zxing-dynamsoft.mp4" poster="https://www.dynamsoft.com/codepool/img/2026/07/barcode-benchmark-python-zxing-dynamsoft-poster.png" controls="controls" muted="muted" style="max-height:640px; min-height: 200px; max-width: 100%;"></video>

## Prerequisites

- Python 3.14 (tested on 3.14.4), `zxing-cpp` 3.1.1, `dynamsoft-capture-vision-bundle` 3.6.5000, OpenCV, and NumPy
- The synthetic barcode corpus and its verified manifest (see [Reproducibility](#reproducibility))
- A valid Dynamsoft license key. [Get a 30-day free trial license](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform).

Install the dependencies:

```powershell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r python/requirements.txt
```

## Step 1: Verify the Synthetic Corpus Manifest

The synthetic barcode corpus is a generated still-image benchmark. Seeded layouts compose BWIPP-generated labels over reusable scenes of packaging, paper, fabric, and work surfaces, then vary payload, placement, view, framing, and background crop. Isolated and combined capture effects cover perspective, rotation, defocus and motion blur, low resolution and contrast, noise, JPEG compression, partial occlusion, uneven illumination, and glare. The manifest records the JPEG hash, seed, applied effects, and each symbol's format, payload, and final-image quadrilateral.

| Corpus stage | Count | Role in the run |
|---|---:|---|
| JPEG images | 8,000 | What each decoder is scored against, including controls |
| Annotated symbols | 11,372 | Ground truth formats and payloads |
| Symbologies | 24 | 13 linear, 4 postal, 7 2D |
| Background scenes | 36 | Reusable packaging, paper, fabric, and work surfaces |
| Background-only controls | 200 | An empty response is a correct image |
| Mixed-symbology images | 153 | Frames carrying several different formats |
| Positive images | 7,800 | Images with 1–16 annotated symbols |
| Decoder records | 24,000 | 8,000 images × 3 readers × 1 measured pass |

The generator bounds projected shape distortion, preserves QR and Micro QR finder patterns, caps occlusion at 22% of a symbol, and ties blur and downsampling to module size. An image-quality screen measures expected dark-to-light transitions from the encoder mask, while perceptual hashes and color thumbnails screen for near-duplicates. These results describe this published corpus.

```sh
python -m pip install -r requirements.txt
npm ci
python generate_by_format.py --output .runs/grouped-base
python expand_corpus.py --base .runs/grouped-base --output .runs/generated-8000
python validate.py --dataset .runs/generated-8000 --expected-images 8000
```

The runner checks `manifest.jsonl` against the SHA-256 stored in `inventory.json` before decoding. A mismatch stops the pass rather than silently scoring a different corpus.

## Step 2: Decode Images with the Python Readers

ZXing-C++ is reached through its PyPI package:

```python
import zxingcpp

results = zxingcpp.read_barcodes(image)
for item in results:
    text = item.text
    barcode_format = item.format.name
```

Dynamsoft Barcode Reader is reached through the Capture Vision bundle's barcode preset:

```python
from dynamsoft_capture_vision_bundle import CaptureVisionRouter, EnumPresetTemplate

router = CaptureVisionRouter()
captured = router.capture(image, EnumPresetTemplate.PT_READ_BARCODES.value)
for item in captured.get_items():
    text = item.get_text()
    barcode_format = item.get_format_string()
```

Only the reader call is timed, recorded as `decode_ns`; OpenCV image loading is tracked separately as `image_load_ns` and never enters the decode statistics. Dynamsoft loads `ReadBarcodes_Default` from the shared preset file and sets `BF_ALL` with one thread per task. ZXing-C++ uses the same explicit format list as the native runner, the `LocalAverage` binarizer, `Plain` text mode, and `Read` for EAN add-on symbols. The Python wheel does not expose `tryHarder` or `maxNumberOfSymbols`.

## Step 3: Run the Benchmark

Point the runner at a Dynamsoft license: a local key file or the `DYNAMSOFT_LICENSE_KEY` environment variable.

```sh
python python/run_benchmark.py \
  --dataset dataset-by-format \
  --output results/python \
  --license-file licenses/dynamsoft-dbr.txt
```

Both readers get 24 warm-up calls before the measured pass, and decoder order is shuffled per image with a seeded PRNG. Runs are resumable: the runner detects (sample, decoder, repetition) records already present in `results.jsonl` and skips them, so an interrupted pass picks up where it stopped instead of re-decoding.

## Step 4: Validate and Score Results

Every image-and-decoder pair appends one record to `results.jsonl`. The append-only stream keeps long runs resumable; `run.json` stores the manifest hash, raw results hash, decoder versions, settings, and environment.

```sh
python python/score.py --run results/python --output review/python/summary.json
python report.py --python-run results/python
```

Validation covers the record schema, image and ground truth counts, repetition consistency, decoder versions, summary totals, and explicit decoder errors. The shared scorer requires all 8,000 images and 11,372 annotated symbols to be present for all three readers before it publishes a number.

## Step 5: Inspect Accuracy and Decode Time

Each decoder made one timed pass over all 8,000 images on Windows 11 with Python 3.14.4, OpenCV 5.0.0.93, NumPy 2.5.4, an Intel Core i5-13400F with 16 logical processors, and one benchmark process.

| Decoder | Exact images | Image accuracy | Symbol recall | Precision | Wrong-read images | No read | Incomplete | Mean | Median | P95 |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| Dynamsoft Barcode Reader 3.6.5000 | **6,701 / 8,000** | **83.76%** | **84.96%** | 98.88% | 103 | 827 | 369 | 51.88 ms | 26.06 ms | 152.30 ms |
| ZXing-C++ 3.1.1 | 3,852 / 8,000 | 48.15% | 49.38% | **98.93%** | 56 | 3,828 | 264 | **14.12 ms** | **10.53 ms** | **43.57 ms** |

Failures are split into **wrong-read images** (at least one unmatched prediction), **no-read images** (expected symbols and zero matches), and **incomplete images** (some matches, no unmatched predictions). An SDK error counts as no read. None of the three readers produced a prediction on any of the 200 background-only controls. At least one reader decoded 9,831 of the 11,372 annotated symbols, leaving 1,067 supported symbols unread by all three and 474 symbols outside every Python reader's format list.

The headline gap is coverage: DBR matched **4,046 more annotated symbols** and produced **2,849 more exact images**, a **35.61 percentage point** lead in image accuracy. Across the 11 symbologies all three Python readers implement, recall is 94.26% for DBR, 76.39% for ZXing-C++ and 76.89% for PyZBar, which isolates how much of the raw difference comes from format coverage rather than decode quality. ZXing-C++ keeps a clear latency advantage — 14.12 ms mean versus 51.88 ms — and a 0.05 percentage point precision edge. Treat these as a measured trade-off on this curated corpus, not a universal ranking for every barcode workload.

Difficulty shows up in the scenario breakdown. DBR scored 90.98% exact images on clean labels, 77.10% under perspective, 75.93% under partial occlusion, and 70.97% on combined effects. ZXing-C++ scored 56.59%, 52.74%, 52.18%, and 31.18% on the same groups. Frames with four annotated symbols were exact on 31.6% of images for DBR and 15.8% for ZXing-C++.

Scoring normalizes UPC-A to its zero-prefixed EAN-13 equivalent, expands UPC-E, folds CODE_39 extensions and ITF14 into their base formats, strips GS1-128 / CODE_128 `]C1`, `{GS}`, and `{FNC1}` markers, strips Codabar start/stop characters, and removes postal check characters when they validate. The matcher also recovers `GS1_128` from ZXing's `]C1` symbology identifier. Each unmatched prediction counts against precision, and barcode location is not part of the score.

Dynamsoft, the developer of Dynamsoft Barcode Reader, built and published this benchmark. The corpus generator, manifest hashes, exclusion and curation rules, decoder settings, raw records, and the generated report all ship with the project so anyone can re-check the comparison.

The generated HTML report lists every no-read and incomplete filename by reader, links to the original JPEG, shows the annotations and returned values, and reports per-symbol recall, precision, format coverage, multi-code results, and false positives on the controls.

## Python vs C++ and JavaScript: Same Corpus, Different Runtimes

The [C++](https://www.dynamsoft.com/codepool/benchmark-barcode-reading-cpp-zxing-dynamsoft-barcode-reader.html) and [JavaScript](https://www.dynamsoft.com/codepool/benchmark-barcode-reading-javascript-zxing-wasm-dynamsoft-barcode-reader.html) runs score the identical 8,000-image manifest with the same matching rules. Only the runtime, the image path, and the SDK packaging change.

| Decoder | Run | Exact images | Image accuracy | Symbol recall | Precision | Mean decode time |
|---|---|---:|---:|---:|---:|---:|
| Dynamsoft Barcode Reader | C++ / Linux 11.6.50.29329 | 6,714 / 8,000 | 83.93% | 85.05% | 98.80% | 39.11 ms |
| Dynamsoft Barcode Reader | Python 3.6.5000 | 6,701 / 8,000 | 83.76% | 84.96% | 98.88% | 51.88 ms |
| Dynamsoft Barcode Reader | JavaScript 11.6.5000 | 6,496 / 8,000 | 81.20% | 82.39% | 99.25% | 118.28 ms |
| ZXing-C++ | C++ / Linux 3.1.1 | 3,852 / 8,000 | 48.15% | 49.38% | 98.93% | 8.60 ms |
| ZXing-C++ | Python 3.1.1 | 3,852 / 8,000 | 48.15% | 49.38% | 98.93% | 14.12 ms |
| zxing-wasm | JavaScript 3.1.2 | 3,851 / 8,000 | 48.14% | 49.38% | 98.96% | 25.63 ms |

The ZXing-C++ core lands within 0.01 percentage points across all three bindings. DBR's native and Python runs are within 0.17 points, while the browser bundle gives up roughly 2.5 points to its JPEG → `ImageBitmap` → RGBA canvas path and records three decode timeouts. Decode times are not directly comparable across runtimes: the C++ run used Ubuntu 24.04 under WSL2, the Python run used Windows 11, and the browser adds canvas and WASM boundary overhead that neither native path has.

## Accuracy Metrics

Image accuracy measures whole images where every expected symbol matched and no extra prediction appeared; symbol recall measures how completely a reader covers the barcodes that actually exist; precision measures how trustworthy its answers are when it reports one:

```text
Image accuracy = exact images / 8,000 images
Symbol recall = matched ground truth symbols / 11,372 annotated symbols
Precision = matched symbols / (matched symbols + unmatched predictions)
```

A no-read or incomplete image means at least one expected symbol went unread, so it pulls recall down without touching precision unless an unmatched prediction was also returned. An `extra_result`, `wrong_text`, or `wrong_format` prediction matches no ground truth barcode, so it pulls precision down.

## Matching Rules

- Ground truth and predictions are matched one to one as multisets.
- The key is canonical barcode format plus exact normalized payload.
- UPC-A and the equivalent zero-prefixed EAN-13 value are treated as equal; UPC-E is expanded.
- CODE_39 extensions and ITF14 fold into their base formats.
- GS1-128 / CODE_128 leading `]C1`, `{GS}`, `{FNC1}`, and ASCII GS markers are stripped before scoring.
- Codabar start/stop characters and validated postal check characters are removed before scoring.
- HTML entities, trailing newlines, and escaping are normalized before scoring.
- ZXing `GS1_128` results are recovered from the `]C1` symbology identifier.
- Barcode location is not part of the score; unsupported formats remain visible in coverage-adjusted metrics.
- Decoder errors and input pipeline errors are explicit outcomes.

## Common Issues & Edge Cases

- **The `zxingcpp` package is missing:** Install it with `pip install -r python/requirements.txt`. The runner reads its version from package metadata.
- **DBR fails during initialization:** Supply a valid license through a local key file or the `DYNAMSOFT_LICENSE_KEY` environment variable, and confirm the shared preset file is present.
- **The manifest hash does not match:** Regenerate the corpus with `generate_by_format.py` and `expand_corpus.py`, then run `validate.py`. The runner refuses to score an unverified manifest.
- **A run stops before completion:** Launch the same command again with `--resume`. The runner recognizes finished (sample, decoder, repetition) records and resumes past them instead of re-decoding.

## When to Choose Dynamsoft Barcode Reader or ZXing-C++

| | Best fit | Poor fit |
|---|---|---|
| **Dynamsoft Barcode Reader 3.6.5000** | Pipelines that cannot afford missed reads, postal and industrial symbologies, dense multi-symbol frames, damaged or blurred labels, configurable templates and support | Workloads where the decode budget must stay near 15 ms per image |
| **ZXing-C++ 3.1.1** | Open-source baselines, inspectable source, controlled inputs limited to its 16 supported formats, latency-sensitive scripts | Frames containing DotCode, MSI, Pharmacode, or postal codes it cannot decode |

If your Python pipeline cannot afford missed reads, Dynamsoft Barcode Reader is the stronger fit in this benchmark: it returned **2,849 more exact images** on the corpus, and that margin matters most on damaged labels, crowded scenes, and mixed-symbology captures. It also brings configurable capture templates, packaged runtime assets, and commercial support.

If you want an engine you can inspect, patch, and ship without license fees, `zxing-cpp` remains a solid option. Its **98.93% precision** and **14.12 ms mean decode time** in this run show its answers are trustworthy and fast when it finds one. Because each reader installs with pip and runs from the same script, the decision comes down to format coverage, recall tolerance, and licensing rather than integration effort.

## Conclusion

This project shows that a Python benchmark can carry the same audit trail as the native build: the manifest verification, resumable JSONL records, raw results hash, environment snapshot, and generated HTML report let any reviewer reproduce the accuracy and decode-time numbers above. Paired with the C++ and JavaScript runs on the identical manifest, it also isolates how much a language binding and image path move those numbers on unchanged input.

## Reproducibility

The manifest, the raw records, and the report are published, so the accuracy and precision above can be recomputed line by line rather than taken on trust.

- **Manifest.** The same 8,000-image manifest as the C++ and JavaScript companions — 11,372 annotated symbols, SHA-256 recorded in `inventory.json` and `run.json`. The corpus generator and validation commands are documented in the corpus README.
- **Raw records.** `results/python/results.jsonl` holds one record per image per decoder; `run.json` records the results SHA-256, decoder versions, settings, and environment.
- **Validation.** `python/score.py` fails the run when record keys, versions, counts, ground-truth consistency, or repetitions disagree.
- **Environment.** `results/python/environment.json` pins the Python interpreter, the OpenCV and NumPy versions, the `zxing-cpp` wheel, and the `dynamsoft-capture-vision-bundle` version.
- **Source.** [Complete benchmark project on GitHub](https://github.com/Dynamsoft/datasets-from-dynamsoft/tree/main/synthetic-benchmark).

Diff your `results.jsonl` against the published one and any disagreement resolves to pixels, configuration, or package version — the three things the manifest and the summary already record.
