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的处理,很多东西并不需要我们过多深入的去探讨,现在需要完全抛弃现有的算法程序,需要从内存中一个字 ...
随机推荐
- JSP的三种注释方式
HTML注释(输出注释):指在客户端查看源代码时能看见注释.例如, <!-- this is an html comment.it will show up int the response. ...
- python模块安装报错 :error: command 'gcc' failed with exit status 1
参考:http://blog.csdn.net/fenglifeng1987/article/details/38057193 解决方法 yum install gcc libffi-devel py ...
- 深入剖析MSAA
本文打算对MSAA(Multisample anti aliasing)做一个深入的讲解,包括基本的原理.以及不同平台上的实现对比(主要是PC与Mobile).为了对MSAA有个更好的理解,所以写下了 ...
- HTML5 使用FileReader实现调用相册、拍照功能
HTML5定义了FileReader作为文件API的重要成员用于读取文件,根据W3C的定义,FileReader接口提供了读取文件的方法和包含读取结果的事件模型. FileReader的使用方式非常简 ...
- webstorm工具的字体、主题等相关设置
Ctrl + /:单行注释Ctrl + Shift + /:块注释Ctrl + Alt + ↓:向下复制当前行Alt + ↑:向上移动Alt + ↓:向下移动Ctrl + D:删除当前行Ctrl + ...
- 【NOIP2012】疫情传递
题解 这题是真的烦... 越来越心疼2012年的dalao们了[不过好像dalao们都不需要本蒟蒻的心疼2333] 其实这题还有点半懂不懂... 所以把洛谷上一个比较好的题解粘过来记忆一下233 1. ...
- (4程序框架)从零开始的嵌入式图像图像处理(PI+QT+OpenCV)实战演练
从零开始的嵌入式图像图像处理(PI+QT+OpenCV)实战演练 1综述http://www.cnblogs.com/jsxyhelu/p/7907241.html2环境架设http://www.cn ...
- 腾讯windows系统服务器
今天用腾讯的服务器搭建起了自己的博客,先看主页效果...简单的ui设计,主要就是要上服务器看看. 说说服务器的搭建: 1.卖,进腾讯云,自己对应的买操作系统的就可以的啦.具体的链接: https ...
- python基础之实现sql增删改查
# encoding:utf-8 # Author:"richie" # Date:2017/8/2 import re key_l = ['id', 'name', 'age', ...
- 【括号问题】$("li:lt(" + (idx + 1) + ")") 手风琴效果注意事项
$("li:lt(" + (idx + 1) + ")").each(function(i){ 注意,这里必须要加括号,是因为如果不加,idx与前面 &quo ...