试试python3.6.2(没有anaconda)它工作知道,here is result on python 3.6.2 without conda
~\Projects\Opencv\python\QR-Code-Projects\QR-Code [ ] 11:46:50
➜ python .\Test_pyZbar.py
-----------------------------
python Verion: 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)]
-----------------------------
Data: Some data
BBox: Rect(left=40, top=40, width=210, height=210)
~\Projects\Opencv\python\QR-Code-Projects\QR-Code [ ] 11:48:49
not working on conda
使用 conda env(二维码)python3.6 输出终端。
File "C:\minconda\envs\QR-code\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
~\Projects\Opencv\python\QR-Code-Projects\QR-Code [ QR-code ] 11:49:08
➜
import cv2
import sys
from pyzbar.pyzbar import decode, ZBarSymbol
print("-----------------------------")
print('python Verion: ', sys.version)
print("----------------------------")
# Image.open('barcode1.png') # if use PIL library
im = cv2.imread("Code.png") # if use cv2
# codes = decode(im, symbols=[ZBarSymbol.QRCODE]) # specify code type
codes = decode(im) # auto detect code type
# print('Decoded:', codes)
for code in codes:
data = code.data.decode('ascii')
print('Data:', code.data.decode('ascii'))
# print('Code Type:', code.type)
print('BBox:', code.rect)
x, y, w, h = code.rect.left, code.rect.top, \
code.rect.width, code.rect.height
cv2.rectangle(im, (x, y), (x+w, y+h), (255, 0, 0), 8)
# print('Polygon:', code.polygon)
cv2.rectangle(im, code.polygon[0], code.polygon[1],
(0, 255, 0), 4)
txt = '(' + code.type + ') ' + data
cv2.putText(im, txt, (x - 10, y - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 50, 255), 2)
text1 = 'No. Codes: %s' % len(codes)
cv2.putText(im, text1, (5, 15),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imshow('bounding box', im)
cv2.waitKey(0)
cv2.destroyAllWindows()