NV12格式是yuv420格式的一种,NV12格式的u,v排布顺序为交错排布,假如一幅图像尺寸为W*H,则先Y分量有W*H个,然后U分量和V分量交错排布,U分量和V分量各有W*H/4个,U,V加起来总数是Y分量的一半。

NV12内存YUV分量排布如下所示:

下面是CUDA实现的NV12格式到BGR格式的转换代码。StepY,StepUV分别为ffmpeg解码出的源数据中的Y分量一行的宽度和UV分量一行的宽度,比实际的图像宽度要大。

__global__ void YCrCb2RGBConver(uchar *pYdata, uchar *pUVdata,int stepY, int stepUV, uchar *pImgData, int width, int height, int channels)
{
const int tidx = blockIdx.x * blockDim.x + threadIdx.x;
const int tidy = blockIdx.y * blockDim.y + threadIdx.y; if (tidx < width && tidy < height)
{
int indexY, indexU, indexV;
uchar Y, U, V;
indexY = tidy * stepY + tidx;
Y = pYdata[indexY]; if (tidx % == )
{
indexU = tidy / * stepUV + tidx;
indexV = tidy / * stepUV + tidx + ;
U = pUVdata[indexU];
V = pUVdata[indexV];
}
else if (tidx % == )
{
indexV = tidy / * stepUV + tidx;
indexU = tidy / * stepUV + tidx - ;
U = pUVdata[indexU];
V = pUVdata[indexV];
} pImgData[(tidy*width + tidx) * channels + ] = uchar (Y + 1.402 * (V - ));
pImgData[(tidy*width + tidx) * channels + ] = uchar (Y - 0.34413 * (U - ) - 0.71414*(V - ));
pImgData[(tidy*width + tidx) * channels + ] = uchar (Y + 1.772*(U - ));
}
}

CPU版本如下:

void YCrCb2RGBConver(uchar *pYdata, uchar *pUVdata, int stepY, int stepUV, uchar *pImgData, int width, int height, int channels)
{ for (int i = ; i < height; i++)
{
for (int j = ; j < width; j++)
{
int indexY, indexU, indexV;
uchar Y, U, V;
indexY = i * stepY + j;
Y = pYdata[indexY]; if (j % == )
{
indexU = i / * stepUV + j;
indexV = i / * stepUV + j + ;
U = pUVdata[indexU];
V = pUVdata[indexV];
}
else if (j % == )
{
indexV = i / * stepUV + j;
indexU = i / * stepUV + j - ;
U = pUVdata[indexU];
V = pUVdata[indexV];
} pImgData[(i*width + j) * channels + ] = uchar(Y + 1.402 * (V - ));
pImgData[(i*width + j) * channels + ] = uchar(Y - 0.34413 * (U - ) - 0.71414*(V - ));
pImgData[(i*width + j) * channels + ] = uchar(Y + 1.772*(U - ));
}
}
}

NV12格式转RGB的CUDA实现的更多相关文章

  1. YUV格式与RGB格式

    YUV420介绍: YUV420格式是指,每个像素都保留一个Y(亮度)分量,而在水平方向上,不是每行都取U和V分量,而是一行只取U分量,则其接着一行就只取V分量,以此重复(即4:2:0, 4:0:2, ...

  2. OpenGL实现相机视频NV21格式转RGB格式

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  3. YUYV格式到RGB格式的转换

    为什么YUYV格式要转到RGB格式,视频的显示调用的多数API都是基于RGB格式,所以需要进行格式的转换. YUYV格式如下: Y0U0Y1V0 Y2U1Y3V1.......... 说明:一个Y代表 ...

  4. Qt 使用openGL 渲染NV12格式的视频

    直接上代码 Nv12Render.h #ifndef NV12RENDER_H #define NV12RENDER_H #include <QOpenGLFunctions> #incl ...

  5. 基于pcl 和 liblas 库 las与pcd格式(rgb点)相互转换(win10 VS2013 X64环境 )

    #include <liblas/liblas.hpp> #include <iomanip> #include <iostream> #include <s ...

  6. YUV格式转换RGB(基于opencv)

    在编写代码将需要处理YUV格从每个视频帧中提取,然后将其保存为图片.有两种常见的方法在线,第一种是通过opencv自带cvCvtColor,可是这样的方法有bug.得到的图片会泛白.另外一种方法是公式 ...

  7. YV12和NV12格式

    害怕搞忘 直接保存图片

  8. 【视频处理】YUV与RGB格式转换

    YUV格式具有亮度信息和色彩信息分离的特点,但大多数图像处理操作都是基于RGB格式. 因此当要对图像进行后期处理显示时,需要把YUV格式转换成RGB格式. RGB与YUV的变换公式如下: YUV(25 ...

  9. YUV和RGB格式分析

    做嵌入式项目的时候,涉及到YUV视频格式到RGB图像的转换,虽然之前有接触到RGB到都是基于opencv的处理,很多东西并不需要我们过多深入的去探讨,现在需要完全抛弃现有的算法程序,需要从内存中一个字 ...

随机推荐

  1. dJango前言之 socketserver源码

    socketserver源码分析: ftpserver=socketserver.ThreadingTCPServer(('127.0.0.1',8080),FtpServer) ftpserver. ...

  2. Pycharm使用总结

    1.代码整体向右移动 按住Win+TAB可以快速向右缩进一个tab 的距离,按住Shift + TAB反方向前进一个TAB距离 2.Model加入get,set 方法 在编辑框中右击,选择genera ...

  3. ABAP开发人员未来应该学些什么

    2007年1月我大学毕业进入SAP Chengdu从事开发工作,到今天已经整整11年了. 这张图在ABAP开发圈子里曾广为流传: 为了避免这种窘境发生在ABAPer身上,我们应该做点什么呢? 2017 ...

  4. The `XXXX` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-game-desktop/Pods-game-desktop.release.xcconfig'. This can lead to prob

    The `game-desktop [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Po ...

  5. hive问题: For direct MetaStore DB connections, we don't support retries at the client level

    已经配置好hive,mysql作为元数据的数据库.在hive中执行drop语句出错: drop table mytest; 错误提示如下: FAILED: SemanticException Unab ...

  6. Redis进阶实践之二如何在Linux系统上安装安装Redis

    一.引言      上一篇文章写了"如何安装VMware Pro虚拟机"和在虚拟机上安装Linux操作系统.那是第一步,有了Linux操作系统,我们才可以在该系统上安装Redis. ...

  7. 从Unity中的Attribute到AOP(四)

    本篇我们将逐一讲解Unity中经常使用的Attribute(Unity对应的文档版本为2018.1b). 首先是Serializable,SerializeField以及NonSerialized,H ...

  8. SharePoint客户端js对象模型

    'use strict'; var context = SP.ClientContext.get_current(); var user = context.get_web().get_current ...

  9. [转]python变量作用域的有趣差别

    func()里 可以访问全局变量i,但不能给i重新赋值. i = 1 def func(): print( i + 1) func() # 2 用global声明后,可以给i重新赋值. i = 1 d ...

  10. 多个tab选项卡

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...