opencv读取一个图片并反色

#include <opencv2\opencv.hpp>
#include <iostream>
#include <string>
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<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]; 


cvShowImage("win1",img);
cvWaitKey(0);
cvReleaseImage(&img);
return 0;
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭