2017-10-07 5 views
2

io.BytesIO()構造体からOPENCVでイメージをロードしようとしています。 はもともと、コードは以下のように、PILで画像をロードします)OpenCvでBytesIOイメージをロード

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(扱っていないようです:

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 3.3とPython 2.7を使用しています。どうか、誰かが私を助けてくれるの?

答えて

1

エンリケはこれを試してみてください :

import numpy as np 

image_stream = io.BytesIO() 
image_stream.write(connection.read(image_len)) 
image_stream.seek(0) 
file_bytes = np.asarray(bytearray(img_stream.read()), dtype=np.uint8) 
img = cv.imdecode(file_bytes, cv.IMREAD_COLOR) 
関連する問題