Ask Your Question

mschoeler's profile - activity

2013-01-23 06:55:47 -0600 received badge  Editor (source)
2013-01-23 06:53:12 -0600 asked a question CV::Mat crashes on release or when out of scope

Hi folks, this is actually not a question but a hint for people having this kind of problem. If you write to an negative matrix element it may seem nothing happened and you still can work with the matrix, manipulate it and do other stuff with it. But as soon as you release it or it gets out of scope it will crash and it is actually very hard to see that this happened, because you accessed a negative matrix or element some time ago. So if you have that kind of problem, check that possibility.

Here is an example code snippet which runs up to the end and crashes

cv::Mat_<float> Tester = cv::Mat_<float>::zeros(1,7);
Tester(-1) = 5; // no crash in this line
Tester(1) = 5;
Tester(2) = 5;
Tester(4) = 5;
Tester(5) = 5;
std::cout << Tester << std::endl; // Output: [0, 5, 5, 0, 5, 5, 0]

Greetings