C++实现NV12格式转BGR
生活随笔
收集整理的這篇文章主要介紹了
C++实现NV12格式转BGR
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
NV12格式:
NV12 轉 BGR 使用opencv接口函數:
cv::cvtColor(img_nv12, img_BGR, cv::COLOR_YUV2BGR_NV12);如果不可調用opencv,使用以下自定義函數實現:
static void NV12_T_BGR(unsigned int width, unsigned int height, unsigned char *yuyv,unsigned char *bgr) {const int nv_start = width * height;int i, j, index = 0, rgb_index = 0;unsigned char y, u, v;int r, g, b, nv_index = 0;for (i = 0; i < height; i++) {for (j = 0; j < width; j++) {nv_index = i / 2 * width + j - j % 2;y = yuyv[rgb_index];u = yuyv[nv_start + nv_index ];v = yuyv[nv_start + nv_index + 1];r = y + ((360 * (v - 128) + 128) >> 8);g = y - (((88 * (u - 128) + 184 * (v - 128)) - 128) >> 8);b = y + ((455 * (u - 128) + 128) >> 8);if (r > 255)r = 255;if (g > 255)g = 255;if (b > 255)b = 255;if (r < 0)r = 0;if (g < 0)g = 0;if (b < 0)b = 0;index = rgb_index % width + i* width;bgr[index * 3 + 2] = r;bgr[index * 3 + 1] = g;bgr[index * 3 + 0] = b;rgb_index++;}}}總結
以上是生活随笔為你收集整理的C++实现NV12格式转BGR的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux上2048游戏程序,如何在Ub
- 下一篇: MENTOR PADS软件菜单显示不完整