cv2.imencode
返回的缓冲区代表什么?
这是 1x1 像素图像的示例。
import cv2
impor numpy as np
img= np.zeros((1,1,3),np.uint8)
en= cv2.imencode('.jpg',img)
print type(en)
<type 'tuple'>
print en[1].shape
(631, 1)
由于某些原因,当图像大小改变时缓冲区大小没有改变:
img= np.zeros((10,10,3),np.uint8)
en= cv2.imencode('.jpg',img)
en[1].shape
(631, 1)
更新:对于更大的图像,它有不同的尺寸。
img= np.zeros((1000,1000,3),np.uint8)
en= cv2.imencode('.jpg',img)
en[1].shape
(16503, 1)
使用随机数据:
img= (np.random.rand(1,1,3)*255).astype(np.uint8)
en= cv2.imencode('.jpg',img)
en[1].shape
(634, 1)
img= (np.random.rand(10,10,3)*255).astype(np.uint8)
en= cv2.imencode('.jpg',img)
en[1].shape
(899, 1)
img= (np.random.rand(1000,1000,3)*255).astype(np.uint8)
en= cv2.imencode('.jpg',img)
en[1].shape
(1175962, 1)
最佳答案
根据 cv2.imencode
文档
Note: cvEncodeImage returns single-row matrix of type CV_8UC1 that contains encoded image as array of bytes.
所以基本上输出取决于您定义的图像格式 .png
、.jpg
等,每种格式都有自己的序列化约定和 cv2.imencode
正是这样做的。它还包含一些与该图像格式相关的元数据,例如:压缩级别等以及像素数据。
关于python - 解释 cv2.imencode 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44328645/