NV212jpg
import cv2
import numpy as np
def NV212RGB(yuv_path, width, height):
with open(yuv_path, 'rb') as f:
yuvdata = np.fromfile(f, dtype=np.uint8)
cv_format = cv2.COLOR_YUV2BGR_NV21
bgr_img = cv2.cvtColor(yuvdata.reshape((height*3//2, width)), cv_format)
return bgr_img
if __name__ == "__main__":
nv21_path = "xxxx/xxx.NV21"
save_path = "xxxx/xxx.jpg"
img = NV212RGB(nv21_path, width, height)
cv2.imwrite(save_path, img)