opencv 兩幅影象直接相減
阿新 • • 發佈:2018-11-05
關鍵函式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;
}