Closed MikeTheWatchGuy closed 6 years ago
Use Google ;)
https://stackoverflow.com/questions/27233351/how-to-decode-a-qr-code-image-in-preferably-pure-python
AFAIK the answers are still valid and we don't have a pure Python QR-Code decoder yet.
I JUST found that package via another thread there! I'm sorry to be a pest I tried installing SIX other packages, all failed, prior to posting here. Honest. Then I went here, downloaded, but finally found I could pip install pyQRCode. Here https://stackoverflow.com/questions/27233351/how-to-decode-a-qr-code-image-in-preferably-pure-python then here http://pyqrcode.sourceforge.net/
Looks like you sent me the SAME link. Drat... I woulda deleted this post 5 minutes from now! Really, I woulda! ;-)
Thank you 10^9 times over!
There seems to be a name clash???
You guys are named qrcode.... but in the PyQRCode examples they show this:
Encoder example:
#!/usr/bin/env python
# coding: utf-8
#
# pyqrcode sample encoder
import sys, qrcode
e = qrcode.Encoder()
image = e.encode('woah!', version=15, mode=e.mode.BINARY, eclevel=e.eclevel.H)
image.save('out.png')
The resulting image is a PIL image. You can do many things with it.
For decoding, you only need to give a filename. Here’s an example:
#!/usr/bin/env python
# coding: utf-8
#
# pyqrcode sample decoder
import sys, qrcode
d = qrcode.Decoder()
if d.decode('out.png'):
print 'result: ' + d.result
else:
print 'error: ' + d.error
Note their imports.
When I import PyQRCode, I can do so, but there's no Decode method, even adding QRCode onto it.
Am I missing something obvious as to these name overlaps?
Crap... wrong 'homepage'
They NEED to take down that example! grrrrr....
And they not only moved pages, but they DELETED all references to "DECODE" on the entire site, in the docs, etc. They don't do decode is how I'm reading it.
Back to 'Google' as you said....
You guys REALLY have your act together. YOU should do a decoder!! It would 'sell' like hotcakes. OK, I would buy it so you've got one customer. LOL. I do like how your stuff just works.
You know that StackOverflow link, where everyone was struggling.... I posted an answer that includes your module as the encoder solution. I posted working code with you as encoder and pyzbar as the decoder.
To some extent this actually tests both modules as one design is producing and the other consuming. The app I posted doesn't compare the results, but does print them out.
Maybe you can use some of this, maybe not, but I'll provide it anyway...
from PIL import Image
import os
import qrcode as qrenc
from pyzbar.pyzbar import decode
DEFAULT_PATH = 'C:\\Python\\PycharmProjects\\QRTEST'
# =-=-=-=-=-=-=-=-=-=- ENCODER =-=-=-=-=-=-=-=-=-=-
with open('DataStream.txt', 'r') as f:
for i, line in enumerate(f.readlines()):
line = line[:-1] # knock off the \n
# Make the QR code from line of text
qr = qrenc.QRCode(
version=None,
error_correction=qrenc.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(line)
qr.make(fit=True)
img = qr.make_image(fit=True)
# save the PNG file
my_file = open(f'in{i:02}.png', 'wb')
img.save(my_file)
# =-=-=-=-=-=-=-=-=-=- DECODER =-=-=-=-=-=-=-=-=-=-
filelist = os.listdir(DEFAULT_PATH)
for f in filelist:
if not f.endswith('.png'):
continue
decoded = decode(Image.open(f))
print(decoded)
Again apologize for posting here is there's a better place to ask a question.
I'm REALLY liking this library you guys have built. It's working beautifully.
I need a reader similar to your writer.
Is there one you recommend?
What do you use to test?
If I can find something that matches up particularly well against python-qrcode then that seems the best way to go with my project.
Thanks for all your efforts.