我USB摄像头采集的到数据是YUV422,显示的话要转成RGB565,看了很多资料,都不明白怎么转的,,谁知道哪有这方面的有用的资料或源码,,我参考一下
RGB565的意思是,16位表示,5位R,6位G,5位B; 转换的公式是,如果,R、G、B的值域为[0,1],转成实数: Y=0.299R+0.587G+0.114B 0<Y<1 Cb=-0.169R-0.331G+0.5G -0.5<G<0.5 Cr=0.5R-0.419g-0.081B -0.5<B<0.5 如果,R、G、B的值域为[0,1],转成二进制: Y=65.481R+128.553G+24.966B+16 16<Y<235 Cb=-37.797R-74.203G+112G+128 -112<G<112 Cr=112R-93.786g-18.214B+128 -112<B<112 当你的数值范围不同时,做个系数变换就行了。 #define RGB(v) ({ \ int value = (v); \ (value > 0) * value | (255 * (value > 255));\ })
YUV444toRGB888 : y = img[0]; u = img[1]; v = img[2]; r = RGB(y + v + (v >> 2) + (v >> 3) + (v >> 5)); g = RGB(y - ((u >> 2) + (u >> 4) + (u >> 5)) - ((v >> 1) + (v >> 3) + (v >> 4) + (v >> 5))); b = RGB(y + u + (u >> 1) + (u >> 2) + (u >> 6));
YUV422toRGB888: y1 = img[0]; u = img[1]; y2 = img[2]; v = img[3]; rgb1 = YUV444toRGB888(y1, u, v); rgb2 = YUV444toRGB888(y2, u, v);
YUV411toRGB888: u = img[0]; y1 = img[1]; y2 = img[2]; v = img[3]; y3 = img[4]; y4 = img[5]; rgb1 = YUV444toRGB888(y1, u, v); rgb2 = YUV444toRGB888(y2, u, v); rgb3 = YUV444toRGB888(y3, u, v); rgb4 = YUV444toRGB888(y4, u, v);
YUV420toRGB888: total = width * height; y = img[py * width + px]; u = img[(py / 2) * (width / 2) + (px / 2) + total]; v = img[(py / 2) * (width / 2) + (px / 2) + total + (total / 4)]; rgb = YUV444toRGB888(y, u, v);
|