Python identifies QR code content

There are three methods for python to identify QR code content, namely pyzbar, zbarlight and zxing. It is unclear whether the underlying algorithm between the first two is the same. The effect of zxing is stronger than the first two algorithms.
The img below is in numpy format.

  1. pizbar
import pyzbar
barcode = pyzbar.decode(img)
(x, y, w, h) = barcode.rect  # 
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
  1. zbarlight
    needs to convert numpy to PIL format.
import zbarlight
from PIL import Image
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
codes = zbarlight.scan_codes(['qrcode'], img)
  1. zxing
    has the best recognition effect.
    It seems that the image needs to be stored locally, and absolute paths cannot be used. Not tested in detail, just used briefly.
import zxing
reader = zxing.BarCodeReader()
barcode = reader.decode('decode.jpg')

Guess you like

Origin blog.csdn.net/a272881819/article/details/123482940