我正在使用pyzbar库解码QR码。现在,我正在尝试使用uMat使此过程更快。问题在于pyzbar解码无法接受umat变量。
文件“ C:\ Python \ lib \ site-packages \ pyzbar \ pyzbar.py”,行175,在解码中 像素,宽度,高度=图片 TypeError:“ cv2.UMat”对象不可迭代
这是我的代码示例
import cv2
import numpy as np
from pyzbar.pyzbar import decode
import matplotlib.pyplot as plt
cv2.ocl.setUseOpenCL(True)
for subdir, dirs, files in os.walk("Images"):
for file in sorted(files):
filepath = subdir + os.sep + file
if filepath.endswith(".JPG"):
image = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
image = cv2.UMat(image)
symbols = decode(image)
if symbols:
plt.title(symbols[0][0])
plt.imshow(image)
plt.show()
答案 0 :(得分:1)
IU可以在pyzbar的解码文档中找到该错误的原因:
def decode(image, symbols=None, scan_locations=False):
"""Decodes datamatrix barcodes in `image`.
Args:
image: `numpy.ndarray`, `PIL.Image` or tuple (pixels, width, height)
symbols (ZBarSymbol): the symbol types to decode; if `None`, uses
`zbar`'s default behaviour, which is to decode all symbol types.
scan_locations (bool): If `True`, results will include scan
locations.
解码期望包含特定顺序的数据的图像或矩阵,由OpenCV支持的mat-instance完全填充。 UMat格式不能满足此要求,因此会发生错误。