OpenCV ycrcb颜色空间
Opencv中有一个Ycrcb的选项,这个选项其实是Yuv444packet.
下面代码从文件中获取到一个yuv444planar的文件,通过手动转换,将其转为YcrCb,然后进行颜色空间csc.
所以可以确定这是一个packet的存储格式
def yuv444p_2_bgr8_opencv(file, w, h):
yuv444p = utils.io.load_file_to_ndarray(file, utils.enum2.PixFmt.Enflame_PIX_FMT_YUV444P, w, h)
ycrcb = np.zeros((3*w*h), np.uint8, 'C')
for j in range(w*h):
ycrcb[j*3+0] = yuv444p[0][j] # Y
ycrcb[j*3+1] = yuv444p[2][j] # cr
ycrcb[j*3+2] = yuv444p[1][j] # cb
tmp = file+'-tmp-mid.bin'
utils.io.save_ndarray_to_file(ycrcb, tmp)
res = backend.cpu.opencv.csc(tmp, utils.enum2.PixFmt.Enflame_PIX_FMT_YCrCb, utils.enum2.PixFmt.Enflame_PIX_FMT_BGR24, w, h)
os.remove(tmp)
return res