yuv to rgb 转换失败呀。天呀。谁来帮帮我呀。
2015-04-28 16:35
399 查看
为了方便提取YUV数据,扫描一帧图像分1,3,5,7,9...........奇数行
和0,2,4,6,8...偶数行。
转换算法是从 http://www.fourcc.org/fccyvrgb.php 中找到,失败了呀!!!!!
图像一看就不对,唉,搞了好几天了,谁来帮忙试一下呀。
void MainWindow::paintEvent(QPaintEvent *e)
{
QPainter tPainter(this);
tPainter.drawText(10,50,"hello");
QString tYUVFile("/home/shell.albert/project/H.264/football/fb001.yuv");
QFile tFile(tYUVFile);
if(!tFile.open(QIODevice::ReadOnly))
{
qDebug()<<"open file failed!";
return;
}
QByteArray tYData=tFile.read(84480);
QByteArray tUData=tFile.read(21120);
QByteArray tVData=tFile.read(21120);
QByteArray tRestData=tFile.readAll();
qDebug()<<"Y:"<<tYData.size();
qDebug()<<"U:"<<tUData.size();
qDebug()<<"V:"<<tVData.size();
qDebug()<<"Rest:"<<tRestData.size();
QImage tImage(352,240,QImage::Format_RGB32);
qint32 tYUVWidth=tImage.width();
#if 1
//1,3,5,7..................
for(qint32 i=1;i<tImage.height();i+=2)
{
for(qint32 j=0;j<tImage.width();j++)
{
qint32 x=i-1;
qint32 y=j;
qint32 tYOffset=x*tYUVWidth+y;
qint32 tUOffset=(x/2)*(tYUVWidth/2)+y/2;
qint32 tVOffset=(x/2)*(tYUVWidth/2)+y/2;
qDebug("1,3,5,7:(%d,%d):%d,%d,%d",i,j,tYOffset,tUOffset,tVOffset);
qint32 tYValue=tYData.at(tYOffset);
qint32 tUValue=tUData.at(tUOffset);
qint32 tVValue=tVData.at(tVOffset);
qint32 tRed=tYValue+1.403*tVValue;
qint32 tGreen=tYValue-0.344*tUValue-0.714*tVValue;
qint32 tBlue=tYValue+1.770*tUValue;
tRed=tRed>255?255:tRed<0?0:tRed;
tGreen=tGreen>255?255:tGreen<0?0:tGreen;
tBlue=tBlue>255?255:tBlue<0?0:tBlue;
tImage.setPixel(j,i,qRgb(tRed,tGreen,tBlue));
}
}
#endif
#if 0
//0,2,4,6,8...............
for(qint32 i=0;i<tImage.height();i+=2)
{
for(qint32 j=0;j<tImage.width();j++)
{
qint32 x=i;
qint32 y=j;
qint32 tYOffset=x*tYUVWidth+y;
qint32 tUOffset=(x/2)*(tYUVWidth/2)+y/2;
qint32 tVOffset=(x/2)*(tYUVWidth/2)+y/2;
qDebug("0,2,4,6:(%d,%d):%d,%d,%d",i,j,tYOffset,tUOffset,tVOffset);
qint32 tYValue=tYData.at(tYOffset);
qint32 tUValue=tUData.at(tUOffset);
qint32 tVValue=tVData.at(tVOffset);
qint32 tRed=1.164*(tYValue-16)+1.596*(tVValue-128);
qint32 tGreen=1.164*(tYValue-16)-0.813*(tVValue-128)-0.391*(tUValue-128);
qint32 tBlue=1.164*(tYValue-16)+2.018*(tUValue-128);
tRed=tRed>255?255:tRed<0?0:tRed;
tGreen=tGreen>255?255:tGreen<0?0:tGreen;
tBlue=tBlue>255?255:tBlue<0?0:tBlue;
tImage.setPixel(j,i,qRgb(tRed,tGreen,tBlue));
}
}
#endif
tPainter.drawImage(0,0,tImage);
tYData.resize(0);
tUData.resize(0);
tVData.resize(0);
}
和0,2,4,6,8...偶数行。
转换算法是从 http://www.fourcc.org/fccyvrgb.php 中找到,失败了呀!!!!!
图像一看就不对,唉,搞了好几天了,谁来帮忙试一下呀。
void MainWindow::paintEvent(QPaintEvent *e)
{
QPainter tPainter(this);
tPainter.drawText(10,50,"hello");
QString tYUVFile("/home/shell.albert/project/H.264/football/fb001.yuv");
QFile tFile(tYUVFile);
if(!tFile.open(QIODevice::ReadOnly))
{
qDebug()<<"open file failed!";
return;
}
QByteArray tYData=tFile.read(84480);
QByteArray tUData=tFile.read(21120);
QByteArray tVData=tFile.read(21120);
QByteArray tRestData=tFile.readAll();
qDebug()<<"Y:"<<tYData.size();
qDebug()<<"U:"<<tUData.size();
qDebug()<<"V:"<<tVData.size();
qDebug()<<"Rest:"<<tRestData.size();
QImage tImage(352,240,QImage::Format_RGB32);
qint32 tYUVWidth=tImage.width();
#if 1
//1,3,5,7..................
for(qint32 i=1;i<tImage.height();i+=2)
{
for(qint32 j=0;j<tImage.width();j++)
{
qint32 x=i-1;
qint32 y=j;
qint32 tYOffset=x*tYUVWidth+y;
qint32 tUOffset=(x/2)*(tYUVWidth/2)+y/2;
qint32 tVOffset=(x/2)*(tYUVWidth/2)+y/2;
qDebug("1,3,5,7:(%d,%d):%d,%d,%d",i,j,tYOffset,tUOffset,tVOffset);
qint32 tYValue=tYData.at(tYOffset);
qint32 tUValue=tUData.at(tUOffset);
qint32 tVValue=tVData.at(tVOffset);
qint32 tRed=tYValue+1.403*tVValue;
qint32 tGreen=tYValue-0.344*tUValue-0.714*tVValue;
qint32 tBlue=tYValue+1.770*tUValue;
tRed=tRed>255?255:tRed<0?0:tRed;
tGreen=tGreen>255?255:tGreen<0?0:tGreen;
tBlue=tBlue>255?255:tBlue<0?0:tBlue;
tImage.setPixel(j,i,qRgb(tRed,tGreen,tBlue));
}
}
#endif
#if 0
//0,2,4,6,8...............
for(qint32 i=0;i<tImage.height();i+=2)
{
for(qint32 j=0;j<tImage.width();j++)
{
qint32 x=i;
qint32 y=j;
qint32 tYOffset=x*tYUVWidth+y;
qint32 tUOffset=(x/2)*(tYUVWidth/2)+y/2;
qint32 tVOffset=(x/2)*(tYUVWidth/2)+y/2;
qDebug("0,2,4,6:(%d,%d):%d,%d,%d",i,j,tYOffset,tUOffset,tVOffset);
qint32 tYValue=tYData.at(tYOffset);
qint32 tUValue=tUData.at(tUOffset);
qint32 tVValue=tVData.at(tVOffset);
qint32 tRed=1.164*(tYValue-16)+1.596*(tVValue-128);
qint32 tGreen=1.164*(tYValue-16)-0.813*(tVValue-128)-0.391*(tUValue-128);
qint32 tBlue=1.164*(tYValue-16)+2.018*(tUValue-128);
tRed=tRed>255?255:tRed<0?0:tRed;
tGreen=tGreen>255?255:tGreen<0?0:tGreen;
tBlue=tBlue>255?255:tBlue<0?0:tBlue;
tImage.setPixel(j,i,qRgb(tRed,tGreen,tBlue));
}
}
#endif
tPainter.drawImage(0,0,tImage);
tYData.resize(0);
tUData.resize(0);
tVData.resize(0);
}
相关文章推荐
- Rgb to Yuv,Tuv to Rgb转换(C# emgucv)
- FFMPEG 实现 YUV,RGB各种图像原始数据之间的转换(swscale)
- 关于YUV和RGB之间的转换公式
- RGB与YUV图像视频格式的相互转换(转)
- RGB与YUV之间的转换
- RGB颜色空间到HSV和YUV的转换关系(含VC代码)
- RGB和YUV之间转换
- 实现RGB,CMY(K),YUV,YIQ,YCbCr颜色的转换算法
- BMP文件读写以及RGB与YUV转换
- 各种RGB和YUV相互转换的代码
- yuv显卡转换rgb
- YUY2(YUV) 与 RGB 格式图片的相互转换 以及 基于YUY2(YUV)的blending
- bayer, yuv, RGB转换方法
- FFMPEG 实现 YUV,RGB各种图像原始数据之间的转换(swscale)
- 古老的YUV视频呈现详解 及 RGB转换
- YUV格式学习:YUV422P、YV16、NV16、NV61格式转换成RGB24
- RGB与YUV转换
- YUV格式详解及 YUV与RGB转换
- FFMPEG 实现 YUV,RGB各种图像原始数据之间的转换(swscale)
- RGB颜色空间与YUV等颜色空间之间的转换单元