函数名:cvAbsDiff
功能: calculates absolute difference between two arrays.
说明:src1 The first source array
src2 The second source array
dst The destination array
dst(i)c = |src1(I)c − src2(I)c |
All the arrays must have the same data type and the same size (or ROI size).
它可以把两幅图的差的绝对值输出到另一幅图上面来。在QQ游戏里面有一款叫做"我们来找茬",就是要找两幅图的不同点,下面是代码实现:
- #include<stdlib.h>
- #include <stdio.h>
- #include <cv.h>
- #include <highgui.h>
- int main(int argc, char*argv[])
- {
- IplImage* img1, *img2,*img3;
- if(argc<3){
- printf("Usage: main <image-file-name>\n\7");
- exit(0);
- }
- img1=cvLoadImage(argv[1]);
- img2=cvLoadImage(argv[2]);
- if(!img1||!img2){
- printf("Could not load image file\n");
- exit(0);
- }
- img3 = cvCreateImage(cvGetSize(img1),img1->depth,img1->nChannels);
- cvAbsDiff(img1,img2,img3);
- cvNamedWindow("img1", CV_WINDOW_AUTOSIZE);
- cvNamedWindow("img2", CV_WINDOW_AUTOSIZE);
- cvNamedWindow("img3", CV_WINDOW_AUTOSIZE);
- cvShowImage("img1", img1 );
- cvShowImage("img2", img2 );
- cvShowImage("img3", img3 );
- cvWaitKey(0);
- cvReleaseImage(&img1);
- cvReleaseImage(&img2);
- cvReleaseImage(&img3);
- return0;
- }
查看效果: