Skip to content
Search

Pyzbar

lastmod 2024-08-02created 2024-08-014 edits

Read one-dimensional barcodes and QR codes from Python 2 and 3.

Example

pip install pyzbar

Example

Assuming a single photo contains several QR codes, if you write code that prints the information of each QR code in the photo and draws a red rectangle over each QR code area,

import cv2
from pyzbar.pyzbar import decode

img = cv2.imread("qrcode_3.jpg")
img = cv2.resize(img, (0, 0), fx=0.3, fy=0.3)
decoded = decode(img)
for d in decoded:
    x, y, w, h = d.rect
    barcode_data = d.data.decode("utf-8")
    barcode_type = d.type
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 5)
    print(barcode_data, barcode_type)

cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

See also

  • QRCode
  • BarCode
  • libzbar - QR Code scanner engine for QR+Emoji
  • zbar-py - zbar package
  • pyzbar - Read one-dimensional barcodes and QR codes from Python 2 and 3.
  • QReader - Robust and Straight-Forward solution for reading difficult and tricky QR codes within images in Python. Supported by a YOLOv8 QR Segmentation model.
  • cv2.QRCodeDetector - QR code detector built into OpenCV.

Favorite site

author Zer0 sitemap