使用方法:
3840*2160是.yuv数据的分辨率
data.raw为yuv格式的raw数据
cv:显示
out.png 不显示,存储的文件名
python3 yuv_2_rgb.py data.raw cv 3840 2160
或
python3 yuv_2_rgb.py data.raw out.png 3840 2160
源码 yuv_2_rgb.py:
import os
import sys
import cv2
import numpy as np
input_name = sys.argv[1]
output_name = sys.argv[2]
img_width = int(sys.argv[3])
img_height = int(sys.argv[4])
with open(input_name, "rb") as src_file:
raw_data = np.fromfile(src_file, dtype=np.uint8, count=img_width*img_height*2)
im = raw_data.reshape(img_height, img_width, 2)
rgb = cv2.cvtColor(im, cv2.COLOR_YUV2BGR_YUYV)
if output_name != 'cv':
cv2.imwrite(output_name, rgb)
else:
cv2.imshow('', rgb)
cv2.waitKey(0)
参考:
Machine vision – Thinking ToastersPosts about Machine vision written by Piotr Goslawskihttps://thinkingtoasters.com/category/machine-vision/
yuvio/README.md at main · labradon/yuvio · GitHubPython package for reading and writing uncompressed yuv image and video data. - yuvio/README.md at main · labradon/yuviohttps://github.com/labradon/yuvio/blob/main/README.md
YUV Colorspacehttps://softpixel.com/~cwright/programming/colorspace/yuv/