void backGroundUpdate(unsigned char *img_b, unsigned char *img_f, float rate)
{
int i,pixelsNum=height*width;
for(i=0;i<PIXELSNUM;I++,IMG_B++,IMG_F++)
*img_b=(unsigned char)((1-rate)*(*img_b)+rate*(*img_f));
}
优化后代码:
void backGroundUpdate(unsigned char *img_b, unsigned char *img_f, float rate)
{
int i,pixelsNum=height*width;
int r=(int)(rate*(1<<10));
for(i=0;i<PIXELSNUM;I++,IMG_B++,IMG_F++)
*img_b=(unsigned char)(((1<<10-r)*(*img_b)+r*(*img_f))>>10);
} |