#include <cv.h> #include <highgui.h> #pragma comment( lib, "cv.lib" ) #pragma comment( lib, "cxcore.lib" ) #pragma comment( lib, "highgui.lib" ) int main() { IplImage *org=cvLoadImage("lena.jpg",1); IplImage *image=cvCloneImage(org); int width=image->width; int height=image->height; int step=image->widthStep; int channel=image->nChannels; uchar* data=(uchar *)image->imageData; int sign=-1; for(int i=0;i<height;i++) { int cycle=10; int margin=(i%cycle); if((i/cycle)%2==0) { sign=-1; } else { sign=1; } if(sign==-1) { margin=cycle-margin; for(int j=0;j<width-margin;j++) { for(int k=0;k<channel;k++) { data[i*step+j*channel+k]=data[i*step+(j+margin)*channel+k]; } } } else if(sign==1) { for(int j=0;j<width-margin;j++) { for(int k=0;k<channel;k++) { data[i*step+j*channel+k]=data[i*step+(j+margin)*channel+k]; } } } } cvNamedWindow("original",1); cvShowImage("original",org); cvNamedWindow("image",1); cvShowImage("image",image); cvSaveImage("image.jpg",image); cvWaitKey(0); cvDestroyAllWindows(); cvReleaseImage(&image); cvReleaseImage(&org); return 0; }
测试图是标准的lena图,效果图如下