Problem accesing a Matrix element opencv c++

Okay, trying to subtract element by element two matrixes. I need to save the value of the elements of one matrix to then subtract the value of the second matrix. The problem comes (I THINK) when I realize I do not know the type value of the elements of the matrix. When debugging it, it just says. DEBUG ERROR abort ()

Images of what Im doing (sorry I am starting in open cv and c++) : (the error debugging appears, as I said when trying to save in tmp variable.
Captura

Next time, it would be better to copy and paste the code segment rather than a photo to reproduce an error. So, can you check whether mapX and arenafondo objects have valid values/images or not? Are there any other error messages on console?

1 Like

Nothing else than this in console:

Exception thrown at 0x00007FF93DD3D759 : Microsoft C ++ Exception: cv :: Exception at memory location 0x0000006390BFB620.
Debug Error!

Alright, most probably you are trying to read an Mat object that you couldn’t actually create.
If you read an image, you might be using a relative path. Try to change this. As I said check those two objects: mapX and arenafondo

Secondly try this approach for further details.

your imageDiff Mat is CV_8UC1, but you access it using imageDiff.at<float>(), which has to be imageDiff.at<uchar>() instead.

typical noob pitfall :wink:

but in general, please try to avoid loops like that, they’re slow and error prone

and again, no screenshots of code or error msgs here please, thank you.

1 Like

Ohh man I love you now is not stopping there!!! Thank god. And one question, why do you know (should I know) that I have to use uchar? can you give me some documentation about that matter?

tutorials, start here