将yuyv格式图像转为IplImage(彩色)
2015-05-17 20:25
85 查看
先介绍下YUYV
贴两篇文章:
摄像头格式为YUYV422,百度百科的介绍:
每个色差信道的抽样率是亮度信道的一半,所以水平方向的色度抽样率只是4:4:4的一半。对非压缩的8比特量化的图像来说,每个由两个水平方向相邻的像素组成的宏像素需要占用4字节内存。
下面的四个像素为:[Y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]
存放的码流为:Y0 U0 Y1 V1 Y2 U2 Y3 V3
映射出像素点为:[Y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3]
YUYV与RGB 之间的转换关系:
R = 1.164*(Y-16) + 1.159*(V-128);
G = 1.164*(Y-16) - 0.380*(U-128)+ 0.813*(V-128);
B = 1.164*(Y-16) + 2.018*(U-128));
源码:
贴两篇文章:
/article/2224576.html
http://blog.chinaunix.net/uid-21410064-id-3248638.html
摄像头格式为YUYV422,百度百科的介绍:每个色差信道的抽样率是亮度信道的一半,所以水平方向的色度抽样率只是4:4:4的一半。对非压缩的8比特量化的图像来说,每个由两个水平方向相邻的像素组成的宏像素需要占用4字节内存。
下面的四个像素为:[Y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]
存放的码流为:Y0 U0 Y1 V1 Y2 U2 Y3 V3
映射出像素点为:[Y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3]
YUYV与RGB 之间的转换关系:
R = 1.164*(Y-16) + 1.159*(V-128);
G = 1.164*(Y-16) - 0.380*(U-128)+ 0.813*(V-128);
B = 1.164*(Y-16) + 2.018*(U-128));
源码:
cvNamedWindow("img_left"); cvNamedWindow("img_right"); // printf("process_image: start_addr:%d \n",addr); // addr stores the address of yuyv data unsigned char* ImgData; int step = img_left->widthStep; //img_left=cvCreateImage(img_size,IPL_DEPTH_8U,3); ImgData = (unsigned char *)img_left->imageData; for(int row=0;row<img_left->height;row++){ for(int col=0;col<(img_left->width);col++){ int tmpCol=3*col; int Yvalue,Uvalue,Vvalue; int tmp; if((row*img_left->width+col)%2==0){ //match yuv value with the address Yvalue=*(unsigned char*)addr; Uvalue=*(unsigned char*)(addr+1); Vvalue=*(unsigned char*)(addr+3); }else{ Yvalue=*(unsigned char*)addr; Uvalue=*(unsigned char*)(addr-1); Vvalue=*(unsigned char*)(addr+1); } //assign the rgb value tmp=1.164*(Yvalue-16)+(1.779*(Uvalue-128)); if(tmp>255) tmp=255; else if(tmp<0) tmp=0; ImgData[row*step+tmpCol] = (unsigned char)tmp; //dig blue tmp=1.164*(Yvalue-16)-0.3455*(Uvalue-128)-0.7169*(Vvalue-128); //dig green if(tmp>255) tmp=255; else if(tmp<0) tmp=0; ImgData[row*step+tmpCol+1]=(unsigned char)tmp; tmp=1.164*(Yvalue-16)+1.4075*(Vvalue-128); //dig red if(tmp>255) tmp=255; else if(tmp<0) tmp=0; ImgData[row*step+tmpCol+2]=(unsigned char)tmp; addr += 2; } }
相关文章推荐
- 通用图像转为IplImage格式
- 通用图像转为IplImage格式
- OpenCV: OpenCV中IplImage图像格式
- [转]OpenCV: OpenCV中IplImage图像格式
- OpenCV中IplImage图像格式与BYTE图像数据的转换
- 图像容器格式互相转换(mat,iplimage*)
- OpenCV中IplImage图像格式
- OpenCV中IplImage图像格式与BYTE图像数据的转换
- 安卓Bitmap图像格式转为BGRA
- 转:OpenCV中IplImage图像格式与 BYTE图像数据的转换
- OpenCV中IplImage图像格式与BYTE图像数据的转换
- 20151210笔记本电话在ubuntu10.04下获取YUYV格式的图像
- OpenCV中IplImage图像格式与 BYTE图像数据的转换
- YUV420数据转为IplImage格式
- 【opencv学习之三】opencv与qt图像格式交换调试问题和补充(IplImage-->QImage)
- IplImage格式图像与byte格式图像数据的相互转换
- C# 如何将PDF转为多种图像文件格式(Png/Bmp/Emf/Tiff)
- 真彩色制式下IplImage转成CBitmap格式
- 【opencv学习之二】opencv与qt图像格式交换IplImage-->QImage
- 访问Mat图像中的每个像素的值和IplImage格式图像中每个像素的值