YUYV 转 RGB 24
来源:互联网 发布:框云计算 编辑:程序博客网 时间:2024/05/17 08:02
直入正题吧,
关于YUYV编码流的官方介绍:
http://linuxtv.org/downloads/v4l-dvb-apis/V4L2-PIX-FMT-YUYV.html
我们一起看看,
YUYV 这种编码
In this format each four bytes is two pixels. Each four bytes is two Y's, a Cb and a Cr. Each Y goes to one of the pixels, and the Cb and Cr belong to both pixels. As you can see, the Cr and Cb components have half the horizontal resolution of the Y component. V4L2_PIX_FMT_YUYV
is known in the Windows environment as YUY2.
每四字节表示两个像素,每四字节有两个Y,一个CB和CR。每一个Y分别属于一个像素,CB和CR共同属于这两个点。这种格式在WINDOWS环境下叫YUY2
字节顺序. 表格中每个单元一个字节
实际分布.
0
1
2
30YCY
YCY1YCY
YCY2YCY
YCY3YCY
YCY
根据这个,用每个点下的值乘换算公式,就可以得到对应RGB下的点,换算公式我就不多说了,讲到这里,直接贴代码把:
//YUV像素 转 RGB像素的函数static void yuv_to_rgb_24(unsigned char y, unsigned char u, unsigned char v,unsigned char* r, unsigned char* g, unsigned char* b){int amp=255;double R,G,B;//conversion equationsB=amp*(0.004565*y+0.000001*u+0.006250*v-0.872);G=amp*(0.004565*y-0.001542*u-0.003183*v+0.531);R=amp*(0.004565*y+0.007935*u-1.088);//R, G and B must be in the range from 0 to 255 if (R < 0)R=0;if (G < 0)G=0;if (B < 0)B=0;if (R > 255)R=255;if (G > 255)G=255;if (B > 255)B=255;*r=(unsigned char)(R);*g=(unsigned char)(G);*b=(unsigned char)(B);}//TODO: width*height这个是图像的长宽,这里默认是24位色深,16位的话,原理一样,不懂留言问我吧。uint8_t * imageLine1;int xx,yy;int x,y;int bpl,Bpp,amp;double r,g,b;unsigned char Y,U,V;unsigned char R,G,B,RG,GB;imageLine1 = (uint8_t *)malloc(width*height*3);bpl=width*3;//bytes per line,Bpp=3;//bytes per pixel,/*TODO: 这里把图像像素组读到videoFrame里,根据自己的情况,从网络,从管道还是从其他地方int ret;ret = read(STDIN_FILENO, videoFrame , width*height*2);*/for (yy = 0; yy < (height); yy++){for (xx =0; xx < (width/2); xx++){x=4*xx;y=yy;U = videoFrame[width*2*y+x+3];V = videoFrame[width*2*y+x+1];Y = videoFrame[width*2*y+x];yuv_to_rgb_24(Y, U, V, &R,&G,&B);imageLine1[(bpl*y)+(Bpp*x/2)]=B;imageLine1[(bpl*y)+(Bpp*x/2)+1]=G;imageLine1[(bpl*y)+(Bpp*x/2)+2]=R;Y = videoFrame[width*2*y+x+2];yuv_to_rgb_24(Y, U, V, &R,&G,&B);imageLine1[(bpl*y)+(Bpp*(x/2+1))]=B;mageLine1[(bpl*y)+(Bpp*(x/2+1))+1]=G;imageLine1[(bpl*y)+(Bpp*(x/2+1))+2]=R;}}
这代码是我从v4l2 sample code改过来的,他们只支持YUV420,不支持YUYV,于是我作了修改。
其他YUV格式的转换思路差不多,有时间的话感觉应该弄个lib,每个刚去接触视频编码的人都要看这个,挺浪费时间的。
- YUYV 转 RGB 24
- yuyv转rgb,rgb转bmp,已验证
- 关于RGB、YUY2、YUYV、YVYU、UYVY、AYUV【转】
- yuyv图像转rgb后转bmp的一个简单demo
- Linux 下V4l2摄像头采集图片,实现yuyv转RGB,RGB转BMP,RGB伸缩,jpeglib 库实现压缩RGB到内存中,JPEG经UDP发送功
- Linux 下V4l2摄像头采集图片,实现yuyv转RGB,RGB转BMP,RGB伸缩,jpeglib 库实现压缩RGB到内存中,JPEG经UDP发送功
- ARM-A8嵌入式综合实训开发记录-YUY2(YUYV)转RGB
- 谈谈RGB、YUY2、YUYV、YVYU、UYVY、AYUV
- RGB、 YUY2、YUYV、YVYU、UYVY与AYUV
- 谈谈RGB、YUY2、YUYV、YVYU、UYVY、AYUV_
- 谈谈RGB、YUY2、YUYV、YVYU、UYVY、AYUV_
- 谈谈RGB、YUY2、YUYV、YVYU、UYVY、AYUV
- 关于RGB、YUY2、YUYV、YVYU、UYVY、AYUV
- RGB、YUY2、YUYV、YVYU、UYVY与AYUV
- 关于RGB、YUY2、YUYV、YVYU、UYVY、AYUV
- RGB、YUY2、YUYV、YVYU、UYVY与AYUV
- 谈谈RGB、YUY2、YUYV、YVYU、UYVY、AYUV
- 谈谈RGB、YUY2、YUYV、YVYU、UYVY、AYUV
- Oracle, 复杂SQL,记录一下,用到了转义字符,左连接技巧
- grub原理及使用详解
- sqite 移植包含嵌入式
- 关于集合中排序有关的比较方式和排序原理
- mpich2读文件出现的问题
- YUYV 转 RGB 24
- Kinect XBOX 360 彩色图像获取和调用
- Hibernate4从入门到精通三——————hibernate的三种状态
- 火狐,IE display兼容性问题解决
- 够专业,就不拍失业(转载)
- XSL 语言入门2 -- 使用XSLT将XML转换为(X)HTML
- 迅时MX8(FXO)8口语音网关连接Elastix+服务器配置
- eclipse 配置maven web项目
- Android学习之 JNI