OpenCV函数学习之cvAbsDiff
cvAbsDiff
Calculates absolute difference between two arrays.
void cvAbsDiff(const CvArr* src1, const CvArr* src2, CvArr* dst);
src1 The first source array
src2 The second source array
dst The destination array
The function calculates absolute difference between two arrays.
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);
return 0;
}
看看效果:
哈哈,看看左下角得图吧,清楚的显示了上面两幅图有4处不同之处,你都看出来了吗?
当然,游戏就是游戏,如果使用作弊手段,那有失去了很多的感情