http://blog.csdn.net/merlin_q/article/details/7024798
版权声明:本文为博主原创文章,未经博主允许不得转载。
#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>using namespace cv;int main(){ Mat img1 = imread("D:\\image\\img1.jpg"); Mat img2 = imread("D:\\image\\img2.jpg");//两幅图像的大小需要一致 Mat img_result1, img_result2, img_result; subtract(img1,img2, img_result1); subtract(img2,img1, img_result2); add(img_result1, img_result2, img_result1); imwrite("D:\\image\\result.jpg", img_result1); imshow("result", img_result1); waitKey(); return 0;}
也可以用 img_result = 2*abs(img1 - img2);
乘以2是要使区别的地方更明显一点。
结果是第三幅图,其中的3,5,6,7,12五处不同的地方。还有什么更好更健壮的方法没 不必图像大小完全一致的?
大家来找茬 两幅图像相减 其它好的实现? 美女找茬
原文:http://www.cnblogs.com/donaldlee2008/p/5331404.html