日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

YUV422转RGB24

發(fā)布時間:2024/4/14 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 YUV422转RGB24 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?????? ? 大部分?jǐn)z像頭的數(shù)據(jù)輸出格式都是YUV格式,而YUV422是比較常見的一種。在Linux下通過攝像頭獲取圖片數(shù)據(jù)并壓縮為jpg格式的圖片,使用libjpeg這個庫,但貌似不能直接壓縮YUV數(shù)據(jù),需要經(jīng)過一些轉(zhuǎn)換,這里先將YUV轉(zhuǎn)換為RGB格式再送給libjpeg進(jìn)行壓縮。

????? ? 下面是YUV422轉(zhuǎn)RGB24的代碼:

1 int convert_yuv_to_rgb_pixel(int y, int u, int v) 2 { 3 unsigned int pixel32 = 0; 4 unsigned char *pixel = (unsigned char *)&pixel32; 5 int r, g, b; 6 r = y + (1.370705 * (v-128)); 7 g = y - (0.698001 * (v-128)) - (0.337633 * (u-128)); 8 b = y + (1.732446 * (u-128)); 9 if(r > 255) r = 255; 10 if(g > 255) g = 255; 11 if(b > 255) b = 255; 12 if(r < 0) r = 0; 13 if(g < 0) g = 0; 14 if(b < 0) b = 0; 15 pixel[0] = r ; 16 pixel[1] = g ; 17 pixel[2] = b ; 18 return pixel32; 19 } 20 21 int convert_yuv_to_rgb_buffer(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height) 22 { 23 unsigned int in, out = 0; 24 unsigned int pixel_16; 25 unsigned char pixel_24[3]; 26 unsigned int pixel32; 27 int y0, u, y1, v; 28 29 for(in = 0; in < width * height * 2; in += 4) 30 { 31 pixel_16 = 32 yuv[in + 3] << 24 | 33 yuv[in + 2] << 16 | 34 yuv[in + 1] << 8 | 35 yuv[in + 0]; 36 y0 = (pixel_16 & 0x000000ff); 37 u = (pixel_16 & 0x0000ff00) >> 8; 38 y1 = (pixel_16 & 0x00ff0000) >> 16; 39 v = (pixel_16 & 0xff000000) >> 24; 40 pixel32 = convert_yuv_to_rgb_pixel(y0, u, v); 41 pixel_24[0] = (pixel32 & 0x000000ff); 42 pixel_24[1] = (pixel32 & 0x0000ff00) >> 8; 43 pixel_24[2] = (pixel32 & 0x00ff0000) >> 16; 44 rgb[out++] = pixel_24[0]; 45 rgb[out++] = pixel_24[1]; 46 rgb[out++] = pixel_24[2]; 47 pixel32 = convert_yuv_to_rgb_pixel(y1, u, v); 48 pixel_24[0] = (pixel32 & 0x000000ff); 49 pixel_24[1] = (pixel32 & 0x0000ff00) >> 8; 50 pixel_24[2] = (pixel32 & 0x00ff0000) >> 16; 51 rgb[out++] = pixel_24[0]; 52 rgb[out++] = pixel_24[1]; 53 rgb[out++] = pixel_24[2]; 54 } 55 return 0; 56 57 }

使用時,調(diào)用convert_yuv_to_rgb_buffer()這個函數(shù)就可以了。關(guān)于這個函數(shù)的參數(shù)解釋如下:
yuv:YUV422數(shù)據(jù)的起始地址

rgb:轉(zhuǎn)換后的數(shù)據(jù)的起始地址

width:攝像頭采集數(shù)據(jù)時所設(shè)置的圖片寬度(如:320)

height:攝像頭采集數(shù)據(jù)時所設(shè)置的圖片高度(如:240)

?

超強(qiáng)干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生

總結(jié)

以上是生活随笔為你收集整理的YUV422转RGB24的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。