我将以下jpeg作为字节码字符串:
jpg = 'b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xfe\x00>CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), default quality\n\xff\xdb\x00C\x00\x08\x06\x06\x07
我想用openCV来处理图像处理。
我试过了:
import numpy as np
from matplotlib import pyplot as plt
nparr = np.fromstring(jpg, np.uint8)
plt.imshow(nparr, cmap='gray')
plt.show()
我得到了:
File "....\lib\site-packages\matplotlib\pyplot.py", line 3205, in imshow
**kwargs)
File "....\lib\site-packages\matplotlib\__init__.py", line 1855, in inner
return func(ax, *args, **kwargs)
File "....\lib\site-packages\matplotlib\axes\_axes.py", line 5487, in imshow
im.set_data(X)
File "....\lib\site-packages\matplotlib\image.py", line 653, in set_data
raise TypeError("Invalid dimensions for image data")
TypeError: Invalid dimensions for image data
我怎样才能使这个工作?