Python 如何将字节数组转换为 OpenCV Mat

How to convert byte array to OpenCV Mat in Python

如何在 Python 中将字节数组转换为 Mat 对象。

import numpy as np

mat = np.asarray(0, 0, data)        
print 'Cols n Row ' + str(mat.cols) + " " + str(mat.rows)

但它不起作用。有人可以帮忙吗。

这样试一试怎么样?可能你需要定义矩阵的数据类型,否则如何将字节数组划分为 'chunks' 将存储在一个单元格中并不明显。

mat = np.asarray(data, dtype=np.uint8)        
print 'Cols n Row ' + str(mat.shape[1]) + " " + str(mat.shape[0])