Tutorial 10 — Barcode, QR Code and OCR Reading with Jetson

Read barcodes, QR codes, and printed text in real time from a live camera feed. Use it for inventory scanning, production line part verification, or automated document processing — all offline on the Jetson.

What you will learn

  • How to decode 1D barcodes and 2D QR codes using pyzbar
  • How to use Tesseract OCR for printed text recognition
  • How to use EasyOCR (GPU-accelerated) for handwritten text
  • How to integrate barcode scanning with an inventory database
  • How to trigger a relay or alert when a specific code is scanned

Step 1 — Run the barcode scanner demo

cd ~/tutorials/10-barcode-qr-ocr
python3 scanner.py --source 0 --show

Hold a barcode or QR code in front of the camera. The decoded value appears as an overlay on the live feed and is printed to the terminal and logged to a CSV file.

Step 2 — Decode barcodes with pyzbar

from pyzbar import pyzbar
import cv2

def scan_barcodes(frame):
    grey   = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    codes  = pyzbar.decode(grey)
    results = []
    for code in codes:
        data  = code.data.decode('utf-8')
        ctype = code.type   # 'QRCODE', 'EAN13', 'CODE128', etc.
        x,y,w,h = code.rect
        cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2)
        cv2.putText(frame, f"{ctype}: {data}", (x, y-10),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0,255,0), 2)
        results.append({'type': ctype, 'data': data})
    return results

Step 3 — Read printed text with EasyOCR (GPU-accelerated)

import easyocr

# GPU-accelerated OCR — pre-configured on your kit
reader  = easyocr.Reader(['en'], gpu=True)
results = reader.readtext(frame)

for (bbox, text, confidence) in results:
    if confidence > 0.5:
        print(f"Text: '{text}'  Confidence: {confidence:.2f}")

Step 4 — Trigger an action when a specific code is scanned

AUTHORIZED_CODES = {"BATCH-2026-001", "BATCH-2026-002"}

def on_scan(code_data):
    if code_data in AUTHORIZED_CODES:
        open_gate()        # trigger relay for authorised part
        log_to_db(code_data, status="PASS")
    else:
        sound_alarm()
        log_to_db(code_data, status="UNKNOWN")

Tutorials 11–20 coming: People Counting, PPE Compliance, Face Blur, YOLO11 Benchmark, TensorRT Export, DeepStream Multi-Camera, MQTT Integration, Grafana Dashboard, Satellite Detection, Custom Training Guide | Back to Jetson Kit

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
0

Subtotal