问题
I have a library of hundreds of pictures from which I need to extract information encoded in a QR code in each picture.
For 70% of the pictures, pyzbar
simply works. For more difficult cases, I try non-linear binarization of the image as suggested by this post: https://stackoverflow.com/a/61443430/1579211
This gets me another 15-20% of the way.
But for about 10% of the images this fails:
from PIL import Image
from pyzbar.pyzbar import decode, ZBarSymbol
from kraken.binarization import nlbin
def read_QRcode(image):
codes = decode(image, symbols=[ZBarSymbol.QRCODE])
if not codes:
codes = decode(nlbin(image), symbols=[ZBarSymbol.QRCODE])
if not codes:
raise RuntimeError(
f'Could not decode a QR code from {image.filename}...'
)
return codes
image = Image.open('sample.jpg')
read_QRcode(image)
When I open up these images (attached sample.jpg
) on the screen, my phone, which has a QR scanner built into the camera app, can decode this QR code correctly (see attached screenshot or try yourself).
Does anyone feel up-to the challenge to help me figure this out?
来源:https://stackoverflow.com/questions/64972169/how-do-i-decode-partially-obscured-qr-codes