我正在尝试从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打开:
我尝试像这样使用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。请问有人可以帮助我吗?
write
、image_len
、seek
和bytearray
。 - Ulrich Stern