core: emit more clear messages in OutputArray::create()

This commit is contained in:
Alexander Alekhin 2020-09-18 15:20:45 +00:00
parent 3e3787ecb6
commit 261ad78122

View File

@ -1247,6 +1247,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
{ {
CV_Assert( i < 0 ); CV_Assert( i < 0 );
Mat& m = *(Mat*)obj; Mat& m = *(Mat*)obj;
CV_Assert(!(m.empty() && fixedType() && fixedSize()) && "Can't reallocate empty Mat with locked layout (probably due to misused 'const' modifier)");
if (allowTransposed && !m.empty() && if (allowTransposed && !m.empty() &&
d == 2 && m.dims == 2 && d == 2 && m.dims == 2 &&
m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] && m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] &&
@ -1260,13 +1261,13 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 ) if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
mtype = m.type(); mtype = m.type();
else else
CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), ""); CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), "Can't reallocate Mat with locked type (probably due to misused 'const' modifier)");
} }
if(fixedSize()) if(fixedSize())
{ {
CV_CheckEQ(m.dims, d, ""); CV_CheckEQ(m.dims, d, "Can't reallocate Mat with locked size (probably due to misused 'const' modifier)");
for(int j = 0; j < d; ++j) for(int j = 0; j < d; ++j)
CV_CheckEQ(m.size[j], sizes[j], ""); CV_CheckEQ(m.size[j], sizes[j], "Can't reallocate Mat with locked size (probably due to misused 'const' modifier)");
} }
m.create(d, sizes, mtype); m.create(d, sizes, mtype);
return; return;
@ -1276,6 +1277,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
{ {
CV_Assert( i < 0 ); CV_Assert( i < 0 );
UMat& m = *(UMat*)obj; UMat& m = *(UMat*)obj;
CV_Assert(!(m.empty() && fixedType() && fixedSize()) && "Can't reallocate empty UMat with locked layout (probably due to misused 'const' modifier)");
if (allowTransposed && !m.empty() && if (allowTransposed && !m.empty() &&
d == 2 && m.dims == 2 && d == 2 && m.dims == 2 &&
m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] && m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] &&
@ -1289,13 +1291,13 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 ) if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
mtype = m.type(); mtype = m.type();
else else
CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), ""); CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), "Can't reallocate UMat with locked type (probably due to misused 'const' modifier)");
} }
if(fixedSize()) if(fixedSize())
{ {
CV_CheckEQ(m.dims, d, ""); CV_CheckEQ(m.dims, d, "Can't reallocate UMat with locked size (probably due to misused 'const' modifier)");
for(int j = 0; j < d; ++j) for(int j = 0; j < d; ++j)
CV_CheckEQ(m.size[j], sizes[j], ""); CV_CheckEQ(m.size[j], sizes[j], "Can't reallocate UMat with locked size (probably due to misused 'const' modifier)");
} }
m.create(d, sizes, mtype); m.create(d, sizes, mtype);
return; return;