subtract one image from another using openCV

marionmaiden picture marionmaiden · Mar 23, 2010 · Viewed 55.6k times · Source

How can I subtract one image from another using openCV?

Ps.: I coudn't use the python implementation because I'll have to do it in C++

Answer

Dat Chu picture Dat Chu · Mar 31, 2010
#include <cv.h>
#include <highgui.h>

using namespace cv;

Mat im = imread("cameraman.tif");
Mat im2 = imread("lena.tif");

Mat diff_im = im - im2;

Change the image names. Also make sure they have the same size.