int i,j,k,sum; int width,height,dep; width=currentimage->width; height=currentimage->height; dep=currentimage->widthStep/currentimage->width; for (i=0;i<height;i++) { for (j=0;j<width;j++) { sum=0; for (k=0;k<dep;k++) { //currentimage->imageData[i*currentimage->widthStep+dep*j+k]-=lastimage->imageData[i*currentimage->widthStep+dep*j+k]; sum+=currentimage->imageData[i*currentimage->widthStep+dep*j+k]; } for (k=0;k<dep;k++) { //currentimage->imageData[i*currentimage->widthStep+dep*j+k]-=lastimage->imageData[i*currentimage->widthStep+dep*j+k]; currentimage->imageData[i*currentimage->widthStep+dep*j+k]=(uchar)(sum/3); } } }
灰度图却有问题:
找到问题了,嘻嘻
sum+=currentimage->imageData[i*currentimage->widthStep+dep*j+k];
currentimage->imageData是char*类型的,应该转化为uchar*
sum+=(uchar)currentimage->imageData[i*currentimage->widthStep+dep*j+k];