【发布时间】:2014-01-26 23:27:36
【问题描述】:
我能够成功地从 zip 加载图像:
with zipfile.ZipFile('test.zip', 'r') as zfile:
data = zfile.read('test.jpg')
# how to open this using imread or imdecode?
问题是:如何在不先保存图像的情况下使用 imread 或 imdecode 打开它以便在 opencv 中进行进一步处理?
更新:
这是我得到的预期错误。我需要将'data'转换成opencv可以使用的类型。
data = zfile.read('test.jpg')
buf = StringIO.StringIO(data)
im = cv2.imdecode(buf, cv2.IMREAD_GRAYSCALE)
# results in error: TypeError: buf is not a numpy array, neither a scalar
a = np.asarray(buf)
cv2.imdecode(a, cv2.IMREAD_GRAYSCALE)
# results in error: TypeError: buf data type = 17 is not supported
【问题讨论】: