Ask Your Question

!fixedSize() error

asked 2015-10-21 05:21:48 -0500

Nbb gravatar image

updated 2015-10-21 05:46:59 -0500

Hi all,

What does this error mean ? The code I am working with is multi threaded with thousands of lines with multiple files. I have no idea how to debug a multithreaded openmp code

OpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() = = Size(_cols, _rows)) in cv::_OutputArray::create, file C:\builds\master_PackSla ve-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line 2171


How do I find the exact line that crashed the code ? The line that stops the code from continuing ? I have an error vector subscript out of range but I am not sure which part of the code I should start looking at

edit retag flag offensive close merge delete



some code tried to change the size of an 'fixed size' Mat, like Matx33d or Vec4f.

try to debug it, let it crash, walk up the call-stack, until you see something familiar. look out for resize(), reshape(), push_back(), anything that messes with the shape/size.

berak gravatar imageberak ( 2015-10-21 07:06:27 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2018-07-31 05:30:49 -0500

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 :)

edit flag offensive delete link more

answered 2017-04-05 05:00:16 -0500

Avio gravatar image

For anybody seeing this obscure message, it happened to me once because at some point in my code I was trying to modify a const cv::UMat &. After a const_cast<cv::UMat &> the problem was solved.

edit flag offensive delete link more


Removing constness from a variable and then modifying it leads to undefined behavior, according to the C++ standard. You nailed the problem but the solution is wrong.

Lorenzo Riano gravatar imageLorenzo Riano ( 2017-10-13 13:57:12 -0500 )edit

Question Tools

1 follower


Asked: 2015-10-21 05:21:48 -0500

Seen: 8,263 times

Last updated: Apr 05 '17