首先使用大家推荐的 zbar
- mac m2 python 3.8 安装无法解析动态库
安装
arch -arm64 brew install zbar
python 使用
from pyzbar.pyzbar import decode
from PIL import Image
if __name__ == '__main__':
file = 'qrcode_prod/492C230613047659_XCXM015492.png'
img_pil = Image.open(file)
res = decode(img_pil)
print(res)
报错如下
File "/Users/jimogangdan/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/pyzbar/pyzbar.py", line 7, in <module>
from .wrapper import (
File "/Users/jimogangdan/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 151, in <module>
zbar_version = zbar_function(
File "/Users/jimogangdan/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 148, in zbar_function
return prototype((fname, load_libzbar()))
File "/Users/jimogangdan/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 127, in load_libzbar
libzbar, dependencies = zbar_library.load()
File "/Users/jimogangdan/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/pyzbar/zbar_library.py", line 65, in load
raise ImportError('Unable to find zbar shared library')
ImportError: Unable to find zbar shared library
- 大意找不到共享库
- github stackoverflow 方案如下 然并卵 不好用
mkdir ~/lib
$ ln -s $(brew --prefix zbar)/lib/libzbar.dylib ~/lib/libzbar.dylib
很多方案失败
- dbr 需要liences
- openmv sensor 需要摄像头识别
终极不要钱的方案 zxingcpp
- 不需要拓展
pip install zxing-cpp
python 代码
img_mpl = plt.imread(file)
np_arr = numpy.array(img_mpl).astype(np.uint8)
results = zxingcpp.read_barcodes(np_arr)
for r in results:
print(f"Text: '{r.text}'")
print(f"Symbology: {r.format.name}")
print(f"Content Type: {r.content_type.name}")
print(f"Bounding Box: {r.position}")
print(f"Rotation: {r.orientation}deg")
print("---")
标签:lib,python,libzbar,pyzbar,mac,M2,print,zbar
From: https://www.cnblogs.com/guanchaoguo/p/17729802.html