欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

C++实现NV12格式转BGR

发布时间:2023/12/14 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。