RGB24-》uyvy的转换

沧海一朵浪 2009-06-11 04:41:51
高分求:我按照网络上的公式,算出来不对啊,请给出源码?
谢谢
...全文
114 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aaaa3105563 2009-06-11
  • 打赏
  • 举报
回复
帮顶·
jtujtujtu 2009-06-11
  • 打赏
  • 举报
回复
不好意思
忘了删除个东西

公式来自于 msdn:

http://msdn2.microsoft.com/en-us/library/ms893078.aspx

//////////////////////////////////////////////////////////////////////////
// RGB2YUV
// pRGB point to the RGB data
// pYUV point to the YUV data
// width width of the picture
// height height of the picture
//////////////////////////////////////////////////////////////////////////
int RGB2YUV(void* pRGB, void* pYUV, int width, int height)
{
if (NULL == pRGB)
{
return -1;
}
unsigned char* pRGBData = (unsigned char *)pRGB;
unsigned char* pYUVData = (unsigned char *)pYUV;
if (NULL == pYUVData)
{
pYUVData = new unsigned char[width*height*2];
}
int R1, G1, B1, R2, G2, B2, Y1, U1, Y2, V1;
for (int i=0; i <height; ++i)
{
for (int j=0; j <width/2; ++j)
{
B1 = *(pRGBData+(height-i-1)*width*3+j*6);
G1 = *(pRGBData+(height-i-1)*width*3+j*6+1);
R1 = *(pRGBData+(height-i-1)*width*3+j*6+2);
B2 = *(pRGBData+(height-i-1)*width*3+j*6+3);
G2 = *(pRGBData+(height-i-1)*width*3+j*6+4);
R2 = *(pRGBData+(height-i-1)*width*3+j*6+5);
Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);
U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);
Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;
V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);
*(pYUVData+i*width*2+j*4) = Y1;
*(pYUVData+i*width*2+j*4+1) = U1;
*(pYUVData+i*width*2+j*4+2) = Y2;
*(pYUVData+i*width*2+j*4+3) = V1;
}
}
return 0;
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jtujtujtu/archive/2009/02/10/3874621.aspx
jtujtujtu 2009-06-11
  • 打赏
  • 举报
回复
公式来自于 msdn:

http://msdn2.microsoft.com/en-us/library/ms893078.aspx

//////////////////////////////////////////////////////////////////////////
// RGB2YUV
// pRGB point to the RGB data
// pYUV point to the YUV data
// width width of the picture
// height height of the picture
//////////////////////////////////////////////////////////////////////////
int RGB2YUV(void* pRGB, void* pYUV, int width, int height)
{
if (NULL == pRGB)
{
return -1;
}
unsigned char* pRGBData = (unsigned char *)pRGB;
unsigned char* pYUVData = (unsigned char *)pYUV;
if (NULL == pYUVData)
{
if (alphaYUV)
{
pYUVData = new unsigned char[width*height*3];
}
else
pYUVData = new unsigned char[width*height*2];
}
int R1, G1, B1, R2, G2, B2, Y1, U1, Y2, V1;
int alpha1, alpha2;
for (int i=0; i<height; ++i)
{
for (int j=0; j<width/2; ++j)
{
B1 = *(pRGBData+(height-i-1)*width*3+j*6);
G1 = *(pRGBData+(height-i-1)*width*3+j*6+1);
R1 = *(pRGBData+(height-i-1)*width*3+j*6+2);
B2 = *(pRGBData+(height-i-1)*width*3+j*6+3);
G2 = *(pRGBData+(height-i-1)*width*3+j*6+4);
R2 = *(pRGBData+(height-i-1)*width*3+j*6+5);
Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);
U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);
Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;
V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);
*(pYUVData+i*width*2+j*4) = Y1;
*(pYUVData+i*width*2+j*4+1) = U1;
*(pYUVData+i*width*2+j*4+2) = Y2;
*(pYUVData+i*width*2+j*4+3) = V1;
}
}
return 0;
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jtujtujtu/archive/2009/02/10/3874621.aspx
随着通信电子技术的迅速发展,信息技术给家居行业产生了深远的影响,家居环境的智能化监控已经成为智能家居的一个重要的发展方向。人们逐渐对自己的生活提出一种更高的要求,他们需要一种智能化、可交互,并且融合现代创新科技的产品来改善他们的生活环境,使他们生活更加安全、舒适、便捷、智能。本文根据智能家居的发展背景和研究现状,并且从实用性和可行性角度出发,研究设计了一种基于STM32单片机的智能家居系统。该系统由一个多功能综合的技术系统组成,各个多功能子系统间具有协同配合能力。基于STM32单片机实现的功能子系统包括:智能温度检测,智能湿度检测,智能烟雾/火灾检测智能检测,无线传输,人机交互机构,风扇调节,报警模块。 整个系统分为前端51单片机采集板和后端STM32单片机接收板。 采集板使用DHT11温湿度传感器、MQ烟雾传感器完成室内家居环境的采集。然后通过nRFL24L01将采集到的数据发送给后端。接收板使用LCD1602完成数据显示、使用蜂鸣器模块报警,使用风扇驱动模块调节室内家居环境。本文完成了智能家居控制系统前端、后端软硬件的设计,使用Altium designer绘制了电路原理图,使用Keil C完成了51单片机和STM32单片机的编程与调试。 最后,对本文设计的基于STM32的智能家居控制系统进行部署调试。试验结果表明,该系统可成功应用在智能家居环境检测调节和火灾安全防护的领域,可提高家居生活智能化水平。

19,464

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧