#include #include "cv.h" #include "cxcore.h" #include "highgui.h" #pragma comment(lib,"cv.lib") #pragma comment(lib,"cxcore.lib") #pragma comment(lib,"highgui.lib") void nega(unsigned char *out, unsigned char *in, int inHeight, int inWidth, int inChannel); int main(){ IplImage *in, *out; int i,j; in = cvLoadImage("./image640.bmp", 0); out = cvCreateImage(cvSize(in->width, in->height), in->depth, in->nChannels); nega((unsigned char*)out->imageData, (unsigned char*)in->imageData, in->height, in->width, in->nChannels); cvNamedWindow("in", 1); cvShowImage("in", in); cvNamedWindow("out", 1); cvShowImage("out", out); cvWaitKey(-1); cvDestroyWindow("in"); cvDestroyWindow("out"); cvReleaseImage( &in ); cvReleaseImage( &out ); return 0; } void nega(unsigned char *out, unsigned char *in, int inHeight, int inWidth, int inChannel){ int i, j; int index; int widthStep; widthStep = inWidth * inChannel; if(widthStep % 4 != 0){ widthStep = widthStep + 4- widthStep%4; } for(i = 0; i < inHeight; ++i){ for(j = 0; j < inWidth; ++j){ index = i * widthStep + j; // ƒlƒKƒ|ƒW”½“] out[index] = 255 - in[index]; } } }