NV12格式转RGB的CUDA实现
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实现的更多相关文章
- YUV格式与RGB格式
YUV420介绍: YUV420格式是指,每个像素都保留一个Y(亮度)分量,而在水平方向上,不是每行都取U和V分量,而是一行只取U分量,则其接着一行就只取V分量,以此重复(即4:2:0, 4:0:2, ...
- OpenGL实现相机视频NV21格式转RGB格式
笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...
- YUYV格式到RGB格式的转换
为什么YUYV格式要转到RGB格式,视频的显示调用的多数API都是基于RGB格式,所以需要进行格式的转换. YUYV格式如下: Y0U0Y1V0 Y2U1Y3V1.......... 说明:一个Y代表 ...
- Qt 使用openGL 渲染NV12格式的视频
直接上代码 Nv12Render.h #ifndef NV12RENDER_H #define NV12RENDER_H #include <QOpenGLFunctions> #incl ...
- 基于pcl 和 liblas 库 las与pcd格式(rgb点)相互转换(win10 VS2013 X64环境 )
#include <liblas/liblas.hpp> #include <iomanip> #include <iostream> #include <s ...
- YUV格式转换RGB(基于opencv)
在编写代码将需要处理YUV格从每个视频帧中提取,然后将其保存为图片.有两种常见的方法在线,第一种是通过opencv自带cvCvtColor,可是这样的方法有bug.得到的图片会泛白.另外一种方法是公式 ...
- YV12和NV12格式
害怕搞忘 直接保存图片
- 【视频处理】YUV与RGB格式转换
YUV格式具有亮度信息和色彩信息分离的特点,但大多数图像处理操作都是基于RGB格式. 因此当要对图像进行后期处理显示时,需要把YUV格式转换成RGB格式. RGB与YUV的变换公式如下: YUV(25 ...
- YUV和RGB格式分析
做嵌入式项目的时候,涉及到YUV视频格式到RGB图像的转换,虽然之前有接触到RGB到都是基于opencv的处理,很多东西并不需要我们过多深入的去探讨,现在需要完全抛弃现有的算法程序,需要从内存中一个字 ...
随机推荐
- Git详解之九:Git内部原理
Git 内部原理 不管你是从前面的章节直接跳到了本章,还是读完了其余各章一直到这,你都将在本章见识 Git 的内部工作原理和实现方式.我个人发现学习这些内容对于理解 Git 的用处和强大是非常重要的, ...
- Ant Design Pro 学习一 安装
安装: 直接 clone git 仓库 $ git clone --depth=1 https://github.com/ant-design/ant-design-pro.git my-projec ...
- JS 对象API之判断父对象是否在子对象的原型链上
语法:父对象.prototype.isPrototypeOf(子对象) 代码栗子: function Student(){ this.name = "小马扎"; ; } var s ...
- 别纠结mybatis啦,赶紧来瞅瞅吧
自从用了mybatis后,被坑的次数不下于无数次,今天我们就来说说最最头疼的错误,看看有多少人入过这个坑呢. 当程序出现了 Result Maps collection already contain ...
- android开发文章收藏
1.activity [Android的从零单排开发日记]之入门篇(四)——Android四大组件之Activity 两分钟彻底让你明白Android Activity生命周期(图文)! 2.serv ...
- 【转】Python 爬虫的工具列表【预】
这个列表包含与网页抓取和数据处理的Python库 网络 通用 urllib -网络库(stdlib). requests -网络库. grab – 网络库(基于pycurl). pycurl – 网络 ...
- SQLAlchemy基础操作一
用前安装 pip3 install sqlalchemy ORM ORM就是运用面向对象的知识,将数据库中的每个表对应一个类,将数据库表中的记录对应一个类的对象.将复杂的sql语句转换成类和对象的操作 ...
- python3之内置函数
1.abs() 取数字的绝对值 >>> print(abs(-28)) 28 >>> print(abs(-2.34)) 2.34 >>> pri ...
- WPF获取窗口句柄的方法
通过WPF的互操作帮助类WindowInteropHelper,相关连接:https://msdn.microsoft.com/zh-cn/library/system.windows.interop ...
- python 豆瓣采集
新手今天刚学python~~~ 有点凌乱~勉强看吧 只能算是给新手看看,见谅 简单版本的 豆瓣采集美图~~~~~~ 美女天天有 有木有~~~ python 3.4 sqlite3 BeautifulS ...