最近在做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++;
}
}
}
打赏帖 | |
---|---|
汽车电子中巡航控制系统的使用被打赏10分 | |
分享汽车电子中巡航控制系统知识被打赏10分 | |
分享安全气囊系统的检修注意事项被打赏10分 | |
分享电子控制安全气囊计算机知识点被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】【OZONE】使用方法总结被打赏20分 | |
【分享开发笔记,赚取电动螺丝刀】【S32K314】芯片启动流程分析被打赏40分 | |
【分享开发笔记,赚取电动螺丝刀】【S32K146】S32DS RTD 驱动环境搭建被打赏12分 | |
【分享开发笔记,赚取电动螺丝刀】【IAR】libc标注库time相关库函数使用被打赏23分 | |
LP‑MSPM0L1306开发版试用结果被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】【LP-MSPM0L1306】适配 RT-Thread Nano被打赏23分 |