“cv2.imdecode(numpyArray, cv2.CV_LOAD_IMAGE_COLOR)” returns None

那年仲夏 提交于 2019-12-06 15:28:50

I have encountered similar problems recently.

The np.fromstring() method returns an 1-D np.array from the parameter string, regardless of the original resource. To use the np.array as an image array in OpenCV, you may need to reshape it according to the image width and height.

Try this:

img_str = np.fromstring ( fig.canvas.tostring_argb(), np.uint8 )
ncols, nrows = fig.canvas.get_width_height()
nparr = np.fromstring(img_str, dtype=np.uint8).reshape(nrows, ncols, 3)
img_np = cv2.imdecode(nparr, cv2.CV_LOAD_IMAGE_COLOR)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!