Ask Your Question

Revision history [back]

I just resolved a situation very much like your own, I was being silly in the following code, where I calculate the reverse condition of matrix N, and am only interested in the return value; I passed a const cv::Mat to hold the output, rather than a cv::Mat without the const specifier.

const cv::Mat ignored;
double cond_N = 1.0/(cv::invert(N,ignored,cv::DECOMP_SVD)); //cond(N)

The result is an exception:

OpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)) in create, file ~/opencv/modules/core/src/matrix.cpp, line 2427

This is resolved, easily, by passing in a non-const cv::Mat to hold the output. (It may also not occur when the Mat so happens to already be the correct size; seeing as the size is what needs modifying from the uninitialized matrix to its output value...)

My problem was fixed by changing const cv::Mat ignored; to cv::Mat ignored;.

The fact I ran into this problem is the result from trying to use const wherever possible, which is in essence a good quality , indicates to readers what my intention with the matrix is, and could even help the compiler optimize, but all things in moderation :)