Hen*_*que 4 python opencv imread
我正在尝试从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)
Run Code Online (Sandbox Code Playgroud)
我尝试用这样的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)
Run Code Online (Sandbox Code Playgroud)
但似乎imread不处理BytesIO().我收到了一个错误.
我正在使用OPENCV 3.3和Python 2.7.拜托,有人能帮帮我吗?
小智 11
Henrique试试这个:
import numpy as np
import cv2 as cv
import io
image_stream = io.BytesIO()
image_stream.write(connection.read(image_len))
image_stream.seek(0)
file_bytes = np.asarray(bytearray(image_stream.read()), dtype=np.uint8)
img = cv.imdecode(file_bytes, cv.IMREAD_COLOR)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6329 次 |
| 最近记录: |