convert 8bit/10bit RGB444,YUV444,NV12,NV21 to PNG
下面的代码写的粗糙(汗~),将就着看,仅做参考。。。
def yuv2bgr(filename,height,width,bit_depth,format_,output_name):
path=os.path.dirname(filename)
base=os.path.basename(filename)
if bit_depth=="8bits":
bpp=1; dtype='uint8'
else:
bpp=2; dtype='uint16'
if format_=="nv21":
cv_format=cv2.COLOR_YUV2BGR_NV21
if format_ == "nv12":
cv_format = cv2.COLOR_YUV2BGR_NV12
with open(filename,'rb') as fp:
frame_len=height*width*bpp*3//2
fp.seek(0,2)
ps=fp.tell()
numfrm=ps//frame_len
fp.seek(0,0)
for i in range(numfrm):
# for i in range(1):
raw = fp.read(frame_len)
yuv = np.frombuffer(raw, dtype=dtype)
yuv