core: emit more clear messages in OutputArray::create()
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Fri, 18 Sep 2020 15:20:45 +0000 (15:20 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Fri, 18 Sep 2020 15:25:29 +0000 (15:25 +0000)
modules/core/src/matrix_wrap.cpp

index d410ab771974071170136c4592382556fc8636c2..8d9e984bc83604493adedd27a3d301cd881cd6f3 100644 (file)
@@ -1247,6 +1247,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
     {
         CV_Assert( i < 0 );
         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() &&
             d == 2 && m.dims == 2 &&
             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 )
                 mtype = m.type();
             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())
         {
-            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)
-                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);
         return;
@@ -1276,6 +1277,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
     {
         CV_Assert( i < 0 );
         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() &&
             d == 2 && m.dims == 2 &&
             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 )
                 mtype = m.type();
             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())
         {
-            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)
-                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);
         return;