How to decode a QR-code image in (preferably pure) Python?

后端 未结 5 1493
时光取名叫无心
时光取名叫无心 2020-12-02 04:10

TL;DR: I need a way to decode a QR-code from an image file using (preferable pure) Python.

I\'ve got a jpg file with a

5条回答
  •  萌比男神i
    2020-12-02 04:46

    I'm answering only the part of the question about zbar installation.

    I spent nearly half an hour a few hours to make it work on Windows + Python 2.7 64-bit, so here are additional notes to the accepted answer:

    • Download https://github.com/NaturalHistoryMuseum/ZBarWin64/releases/download/v0.10/zbar-0.10-cp27-none-win_amd64.whl

    • Install it with pip install zbar-0.10-cp27-none-win_amd64.whl

    • If Python reports an ImportError: DLL load failed: The specified module could not be found. when doing import zbar, then you will just need to install the Visual C++ Redistributable Packages for VS 2013 (I spent a lot of time here, trying to recompile unsuccessfully...)

    • Required too: libzbar64-0.dll must be in a folder which is in the PATH. In my case I copied it to "C:\Python27\libzbar64-0.dll" (which is in the PATH). If it still does not work, add this:

      import os
      os.environ['PATH'] += ';C:\\Python27' 
      import zbar
      

    PS: Making it work with Python 3.x is even more difficult: Compile zbar for Python 3.x.

    PS2: I just tested pyzbar with pip install pyzbar and it's MUCH easier, it works out-of-the-box (the only thing is you need to have VC Redist 2013 files installed). It is also recommended to use this library in this pyimagesearch.com article.

提交回复
热议问题