最近在做DSP图像处理,需要将采集到的图像从YCrCb转换成RGB格式后,进行图像处理,再将RGB图像转换成YCrCb进行显示,下面是我的图像处理的程序,不知道为什么显示出来的结果总是一片黑,求高手指点。
void videoReverse()
{
int i,j,temp;
int r,g,b,y,cr,cb,pr,pg,pb;
Uint8 *Y,*Cr,*Cb;
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
Y=(Uint8 *)(tempYbuffer + i*numPixels + j);
Cr=(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j);
Cb=(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j);
y=(*Y);cr=(*Cr);cb=(*Cb);
y-=16;cr-=128;cb-=128;
r=1.164*y+1.596*cr;
g=1.164*y-0.813*cr-0.392*cb;
b=1.164*y+2.017*cb;
if ( r>255 ) r=255;
else if ( r<0 ) r=0;
if ( g>255 ) g=255;
else if ( g<0 ) g=0;
if ( b>255 ) b=255;
else if ( b<0 ) b=0;
temp=2*g-r-b;
if ( temp>255 ) temp=255;
else if ( temp<0 ) temp=0;
r=abs(temp);g=abs(temp);b=abs(temp);
pr=abs(0.257*r+0.504*g+0.098*b+16);
*(Uint8 *)(tempYbuffer + i*numPixels + j)=pr;
pb=abs(-0.148*r-0.291*g+0.439*b+128);
*(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j)=pb;
pr=abs(0.439*r-0.368*g-0.071*b+128);
*(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j)=pg;
Y++;Cr++;Cb++;
}
}
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
Y=(Uint8 *)(tempYbuffer + i*numPixels + j);
Cr=(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j);
Cb=(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j);
y=(*Y);cr=(*Cr);cb=(*Cb);
y-=16;cr-=128;cb-=128;
r=1.164*y+1.596*cr;
g=1.164*y-0.813*cr-0.392*cb;
b=1.164*y+2.017*cb;
if ( r>255 ) r=255;
else if ( r<0 ) r=0;
if ( g>255 ) g=255;
else if ( g<0 ) g=0;
if ( b>255 ) b=255;
else if ( b<0 ) b=0;
temp=2*g-r-b;
if ( temp>255 ) temp=255;
else if ( temp<0 ) temp=0;
r=abs(temp);g=abs(temp);b=abs(temp);
pr=abs(0.257*r+0.504*g+0.098*b+16);
*(Uint8 *)(tempYbuffer + i*numPixels + j)=pr;
pb=abs(-0.148*r-0.291*g+0.439*b+128);
*(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j)=pb;
pr=abs(0.439*r-0.368*g-0.071*b+128);
*(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j)=pg;
Y++;Cr++;Cb++;
}
}
}
有奖活动 | |
---|---|
“我踩过的那些坑”主题活动——第002期 | |
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |