Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error decode UTF-8 character 'â' #155

Open
Trantamhvbc opened this issue Oct 11, 2023 · 2 comments
Open

Error decode UTF-8 character 'â' #155

Trantamhvbc opened this issue Oct 11, 2023 · 2 comments

Comments

@Trantamhvbc
Copy link

Trantamhvbc commented Oct 11, 2023

I have a problem when I try using pyzbar to decode a QR image. But I had given result don't match data which I using qrcode make before.
this is my code:

from pyzbar.pyzbar import decode
from PIL import Image
from pyzbar.pyzbar import ZBarSymbol
import qrcode
image_path = "my_image.png"
data = 'â'
print(f'data = {data}')
img = qrcode.make(data)
img.save(image_path)
result = decode(Image.open(image_path),symbols=[ZBarSymbol.QRCODE])[0].data.decode("utf-8")
print(f"result = {result}")

@Mrpand4
Copy link

Mrpand4 commented Jul 2, 2024

I'm having the same Issue using it with ã and ç, it seems to be a issue with latin characters
image_binary = take_photo()

nparr = np.frombuffer(image_binary, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)

from PIL import Image

#img = cv2.imread("/content/qrcode lid.png")
barcodes = decode(img)

**** The QR code is the word Associação but pyzbar will return: data=b'Associa\xe7\x99\x9f\xe7\x93\x8ao *****
Thinking it was and encode-decode thing i tried doing several decodes but none return the right result, here is 2 of the most common encodings:

for barcode in barcodes:
try:
text = barcode[0].decode("latin-1") will return Associa��o
text = barcode[0].decode("utf-8") will return Associa癟瓊o
print(text)
except UnicodeDecodeError:
pass

@Mrpand4
Copy link

Mrpand4 commented Jul 2, 2024

I get no issue using the qreader module so if anyone has issues with special characters I suggest using it until this module is updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants