Subtract operation but in c++ code

Hello, I am completely new in opencv and c++ programming and this is my case.
I have Mat image 1 and Mat image2
Want to subtract element by element image 1-image2 and get image 3.
Just as if I was using subtract(image1, image2, image3);
Does anybody know how?

By the way. I am doing this because I tried of course to use subtract function and the program crashed. Dont know why so I am tryng to do this operation a bit more “raw”
Thanks!

please show us the code you tried, and ´the resulting error msg

(also be aware, that those functions require 2 Mats of exactly the same type and size


Debug Error!

Program: …xtr\Desktop\Toxtrac-Git\toxtrac\x64\ToxTrac\Debug\ToxTrac.exe

abort() has been called

The code is simply what I said:

image1 = Mat::zeros(Size(mapX.cols, mapX.rows), CV_8UC1);
image2 = Mat::zeros(Size(mapX.cols, mapX.rows), CV_8UC1);

Mat imageDiff;
imageDiff = Mat::zeros(Size(mapX.cols, mapX.rows), CV_8UC1);
subtract(arena, arenafondo, imageDiff);

uP! Please I need help creating this function :smiley:

read that code carefully. image1, image2 aren’t used. arena and arenafondo aren’t defined.

Well sorry Arena and arenafondo are really image 1 and image2, in my code is written correctly haha SORRY again.

UP! please help me with the funtion :frowning: Im sure it is over the internet already solved but coudnt find it.

what is “UP!” supposed to mean?

Just a way to make my thread be seen in the forum…

that won’t help you at all. in fact it might even do the opposite.

you need to present relevant information. correct code would be a start. a “minimal reproducible example”.