【发布时间】:2026-02-08 13:50:01
【问题描述】:
我正在尝试从 io.BytesIO() 结构加载带有 OPENCV 的图像。 最初,代码使用 PIL 加载图像,如下所示:
image_stream = io.BytesIO()
image_stream.write(connection.read(image_len))
image_stream.seek(0)
image = Image.open(image_stream)
print('Image is %dx%d' % image.size)
我尝试像这样用 OPENCV 打开:
image_stream = io.BytesIO()
image_stream.write(connection.read(image_len))
image_stream.seek(0)
img = cv2.imread(image_stream,0)
cv2.imshow('image',img)
但似乎 imread 不处理 BytesIO()。我遇到了一个错误。
我正在使用 OPENCV 3.3 和 Python 2.7。请问,有人可以帮我吗?
【问题讨论】: