How do I decode partially obscured QR codes?

前提是你 提交于 2021-01-05 08:56:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!