A real-time barcode and QR code detection system built with YOLOv8 and ZXing-CPP. It detects codes from a live webcam feed, decodes them, and automatically looks up product information from multiple online databases — no specialized scanning hardware needed.
The system runs a multi-stage pipeline:
- Detection — YOLOv8 (Small) finds and localizes barcodes and QR codes in the webcam frame with bounding boxes
- Decoding — ZXing-CPP reads the content of the detected code
- Product lookup — the decoded value is queried against 5 product databases to retrieve item information
- Visual feedback — color-coded results on screen:
- 🟢 Green — detected, decoded, and product found
- 🟠 Orange — decoded but product not in database
- 🔴 Red — detected but couldn't decode
- Architecture: YOLOv8-Small (CSPDarknet backbone, PANet neck, 3 detection heads)
- Parameters: ~11.1M trainable
- Input size: 640×640
- Classes: 2 (barcode, qrcode)
- Pre-trained on: COCO, fine-tuned on a custom dataset
- Training: 30 epochs, AdamW optimizer, batch size 16, AMP enabled
- 325 barcode images + 275 QR code images
- 80/20 train/validation split
- Augmentations: rotation (±5°), perspective transform, HSV color jitter
The model uses three detection heads to handle different distances:
- 80×80 feature map → small/distant codes
- 40×40 feature map → medium distance
- 20×20 feature map → close-range codes
- Open Food Facts (World)
- Open Food Facts (Egypt)
- Open Beauty Facts
- Open Pet Food Facts
- Open Products Facts
- Lighting variability — handled with HSV augmentation during training
- Viewing angle — perspective transformation augmentation lets it handle codes up to ~±20° off-axis
- Multiprocessing on Windows — set DataLoader workers=0 to fix PicklingError in Jupyter
- Decode failures — three-tier color feedback so partial detections are still useful
- Python 3
- YOLOv8 (Ultralytics)
- ZXing-CPP for barcode/QR decoding
- OpenCV for webcam capture and visualization
- Open Food/Beauty/Pet Food/Products Facts APIs
Mohammed Tariq, Mazen Abdallah, Malak Elhawary, Maryam Hatem, Ahmed Deaiy, Marvel Fady, Youssef Nashaat