iplimage* yuv420_to_iplimage_opencv(unsigned char* pyuv420, int width, int height)
iplimage *yuvimage,*rgbimg,*yimg,*uimg,*vimg,*uuimg,*vvimg;
int nwidth = width;
int nheight = height;
rgbimg = cvcreateimage(cvsize(nwidth, nheight),ipl_depth_8u,3);
yuvimage = cvcreateimage(cvsize(nwidth, nheight),ipl_depth_8u,3);
yimg = cvcreateimageheader(cvsize(nwidth, nheight),ipl_depth_8u,1);
uimg = cvcreateimageheader(cvsize(nwidth/2, nheight/2),ipl_depth_8u,1);
vimg = cvcreateimageheader(cvsize(nwidth/2, nheight/2),ipl_depth_8u,1);
uuimg = cvcreateimage(cvsize(nwidth, nheight),ipl_depth_8u,1);
vvimg = cvcreateimage(cvsize(nwidth, nheight),ipl_depth_8u,1);
cvsetdata(yimg,pyuv420, nwidth);
cvsetdata(uimg,pyuv420+nwidth*nheight, nwidth/2);
cvsetdata(vimg,pyuv420+long(nwidth*nheight*1.25), nwidth/2);
cvresize(uimg,uuimg,cv_inter_linear);
cvresize(vimg,vvimg,cv_inter_linear);
cvmerge(yimg,uuimg,vvimg,null,yuvimage);
cvcvtcolor(yuvimage,rgbimg,cv_ycrcb2rgb);
cvreleaseimage(&uuimg);
cvreleaseimage(&vvimg);
cvreleaseimageheader(&yimg);
cvreleaseimageheader(&uimg);
cvreleaseimageheader(&vimg);
cvreleaseimage(&yuvimage);
if (!rgbimg)
return rgbimg;
}void copencvdlg::onbnclickedshowimage()
2、採用數學轉換的方式,**如下:
bool yuv420_to_bgr24(unsigned char *puc_y, unsigned char *puc_u, unsigned char *puc_v, unsigned char *puc_rgb, int width_y, int height_y)
//初始化變數
int basesize = width_y * height_y;
int rgbsize = basesize * 3;
byte* rgbdata = new byte[rgbsize];
memset(rgbdata, 0, rgbsize);
/* 變數宣告 */
int temp = 0;
byte* rdata = rgbdata; //r分量位址
byte* gdata = rgbdata + basesize; //g分量位址
byte* bdata = gdata + basesize; //b分量位址
int uvindex =0, yindex =0;
//yuv->rgb 的轉換矩陣
//double yuv2rgb[3][3] = ;
for(int y=0; y < height_y; y++)
}//將r,g,b三個分量賦給img_data
int widthstep = width_y*3;
for (int y = 0; y < height_y; y++)
}if (!puc_rgb)
delete rgbdata;
return true;
}iplimage* yuv420_to_iplimage(unsigned char* pyuv420, int width, int height)
//初始化變數
int basesize = width*height;
int imgsize = basesize*3;
byte* prgb24 = new byte[imgsize];
memset(prgb24, 0, imgsize);
/* 變數宣告 */
int temp = 0;
byte* ydata = pyuv420; //y分量位址
byte* udata = pyuv420 + basesize; //u分量位址
byte* vdata = udata + (basesize>>2); //v分量位址
if(yuv420_to_bgr24(ydata, udata, vdata, prgb24, width, height) == false || !prgb24)
iplimage *image = cvcreateimage(cvsize(width, height), 8,3);
memcpy(image->imagedata, prgb24, imgsize);
if (!image)
delete prgb24;
return image;
yuv轉rgb的函式:
[cpp]view plain
copy
#define mr(y,u,v) (y + (1.403)*(v-128))
#define mg(y,u,v) (y - (0.344) * (u-128) - (0.714) * (v-128) )
#define mb(y,u,v) (y + ((1.773) * (u-128)))
void
yuv420_c_rgb(
char
* pyuv, unsigned
char
* prgb,
intheight,
intwidth)
else
} } }
}
詳解YUV420資料格式
1.yuv簡介 yuv定義 分為三個分量,y 表示明亮度 luminance或luma 也就是灰度值 而 u 和 v 表示的則是色度 chrominance或chroma 作用是描述影像色彩及飽和度,用於指定畫素的顏色。yuv格式 有兩大類 planar和packed。對於planar的yuv格式,...
詳解YUV420資料格式
1.yuv簡介 yuv定義 分為三個分量,y 表示明亮度 luminance或luma 也就是灰度值 而 u 和 v 表示的則是色度 chrominance或chroma 作用是描述影像色彩及飽和度,用於指定畫素的顏色。yuv格式 有兩大類 planar和packed。對於planar的yuv格式,...
yuv420和yuv420p的區別
yv12和i420的區別 在採集到rgb24資料後,需要對這個格式的資料進行第一次壓縮。即將影象的顏色空間由rgb2yuv。因為,x264在進行編碼的時候需要標準的yuv 4 2 0 但是這裡需要注意的是,雖然yv12也是 4 2 0 但是yv12和i420的卻是不同的,在儲存空間上面有些區別。如下...