opencv读取一个图片并反色

#include
#include
#include
using namespace cv;
using namespace std;
int main()
{
IplImage* img = 0; 
int height,width,step,channels;
uchar *data;
int i,j,k; 
 
img=cvLoadImage("aa.jpg",CV_LOAD_IMAGE_COLOR);


    //Mat img = imread("pp.jpg");
    if(!img)
    {
        cout<<"error";
        return -1;
    }


// imshow("xx的靓照",img);
  //  waitKey();


height    = img->height;
width     = img->width;
step      = img->widthStep;
channels  = img->nChannels;
data      = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels); 
 


cvNamedWindow("win1", CV_WINDOW_AUTOSIZE); 
cvMoveWindow("win1", 300, 300); // offset from the UL corner of the screen

for(i=0;i     data[i*step+j*channels+k]=255-data[i*step+j*channels+k]; 


cvShowImage("win1",img);
cvWaitKey(0);
cvReleaseImage(&img);
return 0;
}

你可能感兴趣的:(opencv读取一个图片并反色)