本文主要是介绍yuyv v4l2的数据转换成RGB,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用方法:
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 npinput_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/
这篇关于yuyv v4l2的数据转换成RGB的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!