#include<cv.h>
#include"highgui.h"
int main(int argc, char** argv)
{
IplImage *img =0;
int height,width,channel,step;
uchar *data;
int i,j,k;
if(argc<2)
{
printf("Usage error:please enter your image path.\n");
return -1;
}
if(!img)
{
printf("Could not load img file: %s\n",argv[1]);
return -1;
}
height = img->height;
width = img->width;
step = img ->widthStep;
channel = img ->nChannels;
data = (uchar* )img->imageData;
printf("Processing a %d*%d image with %d channels.\n",height,width,channel );
//create a window
cvNamedWindow("mainWin",CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin",100,100);
//invert the image
for(int i=0;i<height;i++)
for(j=0;j<width;j++)
for(k=0;k<channel;k++)
data[i*step+j*channel+k]=255-data[i*step+j*channel+k];
//show the image
cvShowImage("mainWin",img);
//wait for key
cvWaitKey(0);
//Release the image
cvReleaseImage(&img);
return 0;
}