// 载入图像 img=cvLoadImage("lena.jpg",-1); if(!img) { printf("Could not load image file: %s ",argv[1]); exit(0); } // 获取图像信息 height = img->height; width = img->width; step = img->widthStep; channels = img->nChannels; data = (uchar *)img->imageData; // 反转图像 for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++) data[i*step+j*channels+k]=255-data[i*step+j*channels+k];