Merge pull request #6014 from alalek:fix_5991

pull/6062/head
Vadim Pisarevsky 9 years ago
commit 56c89e0a98
  1. 15
      modules/core/src/matrix.cpp
  2. 8
      modules/core/src/umatrix.cpp
  3. 11
      modules/core/test/test_mat.cpp
  4. 11
      modules/core/test/test_umat.cpp

@ -397,6 +397,14 @@ void Mat::create(int d, const int* _sizes, int _type)
return;
}
int _sizes_backup[CV_MAX_DIM]; // #5991
if (_sizes == (this->size.p))
{
for(i = 0; i < d; i++ )
_sizes_backup[i] = _sizes[i];
_sizes = _sizes_backup;
}
release();
if( d == 0 )
return;
@ -4899,6 +4907,13 @@ void SparseMat::create(int d, const int* _sizes, int _type)
return;
}
}
int _sizes_backup[CV_MAX_DIM]; // #5991
if (_sizes == hdr->size)
{
for(i = 0; i < d; i++ )
_sizes_backup[i] = _sizes[i];
_sizes = _sizes_backup;
}
release();
flags = MAGIC_VAL | _type;
hdr = new Hdr(d, _sizes, _type);

@ -345,6 +345,14 @@ void UMat::create(int d, const int* _sizes, int _type, UMatUsageFlags _usageFlag
return;
}
int _sizes_backup[CV_MAX_DIM]; // #5991
if (_sizes == (this->size.p))
{
for(i = 0; i < d; i++ )
_sizes_backup[i] = _sizes[i];
_sizes = _sizes_backup;
}
release();
if( d == 0 )
return;

@ -1472,3 +1472,14 @@ TEST(Core_Mat_vector, copyTo_roi_row)
EXPECT_EQ(4, (int)dst2[3]);
EXPECT_EQ(5, (int)dst2[4]);
}
TEST(Mat, regression_5991)
{
int sz[] = {2,3,2};
Mat mat(3, sz, CV_32F, Scalar(1));
ASSERT_NO_THROW(mat.convertTo(mat, CV_8U));
EXPECT_EQ(sz[0], mat.size[0]);
EXPECT_EQ(sz[1], mat.size[1]);
EXPECT_EQ(sz[2], mat.size[2]);
EXPECT_EQ(0, cvtest::norm(mat, Mat(3, sz, CV_8U, Scalar(1)), NORM_INF));
}

@ -1343,4 +1343,15 @@ TEST(UMat, testWrongLifetime_Mat)
}
}
TEST(UMat, DISABLED_regression_5991)
{
int sz[] = {2,3,2};
UMat mat(3, sz, CV_32F, Scalar(1));
ASSERT_NO_THROW(mat.convertTo(mat, CV_8U));
EXPECT_EQ(sz[0], mat.size[0]);
EXPECT_EQ(sz[1], mat.size[1]);
EXPECT_EQ(sz[2], mat.size[2]);
EXPECT_EQ(0, cvtest::norm(mat.getMat(ACCESS_READ), Mat(3, sz, CV_8U, Scalar(1)), NORM_INF));
}
} } // namespace cvtest::ocl

Loading…
Cancel
Save