opencv 两幅图像直接相减

关键函数cvAbsDiff()

,代码如下:

#include "cv.h"
#include "highgui.h"
#include "cxcore.h"

int main(int argc,char** argv)
{cvNamedWindow("a",0);
 IplImage* img=cvLoadImage("11.jpg");
 cvShowImage("a",img);

 cvNamedWindow("b",0);
 IplImage* img1=cvLoadImage("12.jpg");
 cvShowImage("b",img1);

 IplImage* diff=cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
 cvAbsDiff(img,img1,diff);
 cvNamedWindow("r",0);
 cvShowImage("r",diff);
 

 while (1)
 {if (cvWaitKey(100)==27) break;
 }

 cvDestroyWindow("a");
 cvDestroyWindow("b");
 cvReleaseImage(&img);
 cvReleaseImage(&img1);
 cvReleaseImage(&diff);
 return 0;
}

你可能感兴趣的:(opencv 两幅图像直接相减)